• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retreaving the value in servlet which is set in session in a jsp page

 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i am having a servlet in which i am fetching datas from a search jsp page(search jsp page contains text boxes and other options on the basis of which user is searched from databse.) all the data from search page are fetched in my servlet by request.getParameter("parameter"). then the database is searched and aray of objects are prepared in same servlet class ..since for searching on the basis of one field there could be more than one user. So an araay is prepared
by EmpJavaBean empJavabeanObjectArray[]=new EmpJavaBean[3];(say)..and in this object fetched fron database are put in.

now i am passing this array into a jsp page through request dispatcher as
<code>

request.setAttribute("substituteArray", empJavabeanObjectArray);
RequestDispatcher rd=request.getRequestDispatcher("/searchedEmpPage.jsp");
rd.forward(request, response);

</code>

there these results are displayed in table with a radio button against each table. user having an option to select any one user and if user select any one user , whole info as object is set in sessssion in that jsp page
as below
<code>
function validateRadio()
{
var thisone=-1;
for(i=0;i<searchedEmpForm.radioGroup.length;i++)
{
if(searchedEmpForm.radioGroup[i].checked==true)
{
thisone=i;
session.setAttribute("fetchedArrayObject[i]",fetchedArrayObject[i]);

}

}
if(thisone==-1)
{
alert("you must select a radio Button");
return false;
}

return true;
}


and in <form name"something" action="same servlet ">

</code>

ie passed again back to servlet . Here only one object is set into session instead of whole array.

i am receiving that object in servlet just nxt to above code of request dispatcher (where i forwarded to 1st jsp page)
as

<code>
EmpJavaBean fetchedEmpJavaBean = new EmpJavaBean();
fetchedEmpJavaBean=(EmpJavaBean)request.getAttribute("fetchedArrayObject[i]");
request.setAttribute("fetchedEmpJavaBean",fetchedEmpJavaBean);
rd=request.getRequestDispatcher("/updateUser.jsp");
rd.forward(request, response);

</code>

note that rd.forward(request, response); is repeated twice in my servlet.

now my moto is that i know how to set the object in session in a jsp page and how to retreive back in servlet.
and from there i want to go to updateUser.jsp page after clicking the radio button (means selecting a user)and pressing submit button. obviously in between it should again comeback to servlet before getting me to updateUser.jsp.
but iam not getting the result and after selecting the radio button and pressing submit button i remain at searchedEmpPage.jsp.

can any one help me please.
i hope iam clear to you guys. my directory structure is ok.
hoping for the response.
thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Secondly, as JavaScript has no notion of the concept of a session, this line of code:is not valid JavaScript and will only cause an error.
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for your inconvinience..actually i am new to any kind of forum..and this is my first post. any way

I have a jsp page...which shows a list of employee fetched from databse.
now user has a option to select any one of employee through radio button.

i want that selection to be passed to a servlet class. how can we do that??

can any body please show it by example

i am using javascript in my code to pick up the selected radio button



thanks.
 
Pradeep Arun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well..I need few more information

What method are you trying to invoke when you select a radio button? i.e with in the Servlet? Also is that method invoked for any other requests?

Thanks,
Pradeep
 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

You have the employee array object.
Iterate the array list within the scriplet.
Within the loop add the radio button having the value as the index .
Ex :


<INPUT TYPE=RADIO NAME="employee" VALUE=<%= i%> >


When the form is posted you can get the index value through which get the selected Employee.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic