Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Fetching Values from previous Page  RSS feed

 
John Vergis
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

scenario: The list of employees is listed to the Administrator who has the option of deleting the record, update the record or change the password.

In the below given snippet rs is the disconnected ResultSet which is passed from the servlet.

******************************************************************
<%
while (rs.next())
{
name = ((rs.getString(2)==null)?" ":rs.getString(2))+ " "+
((rs.getString(3)==null)?" ":rs.getString(3))+ " "+
((rs.getString(4)==null)?" ":rs.getString(4));

phNo = ((rs.getString(5)==null)||("0".equals(rs.getString(5))))?"--":rs.getString(5);

chatId = ((rs.getString(7)==null)||("0".equals(rs.getString(7))))?"--":rs.getString(7);
%>
<tr >
<td>
<FONT COLOR=BLACK FACE='Geneva, Arial' SIZE=3><%= rs.getString(1)%></FONT>
<input type="hidden" name="empName" value="hhfhj" >
</td>
<td>
<FONT COLOR=BLACK FACE='Geneva, Arial' SIZE=3><%= name %></FONT>
</td>
<td>
<FONT COLOR=BLACK FACE='Geneva, Arial' SIZE=3><%= phNo %></FONT>
</td>
<td>
<FONT COLOR=BLACK FACE='Geneva, Arial' SIZE=3><%= rs.getString(6)%></FONT>
</td>
<td>
<FONT COLOR=BLACK FACE='Geneva, Arial' SIZE=3><%= chatId %></FONT>
</td>
<td>
<FONT COLOR=BLACK FACE='Geneva, Arial' SIZE=2>
<a href='<%= request.getContextPath() %>\adminupdate.jsp?empNo=<%= rs.getString(1) %>' target='_self'>Update</a> / <a href='<%= request.getContextPath() %>\admindelemp.jsp?empNo=<%= rs.getString(1) %>&empName=<%= rs.getString(2) %>' target='_self'>Delete </a>/<a href='<%= request.getContextPath() %>\adminchangepswd.jsp?empNo=<%= rs.getString(1) %>&empName=<%= rs.getString(2) %>' target='_self'>Change Pswd </a>  
</FONT>
</td>
</tr>
<%
}
%>

******************************************************************



For updation of the employee details, On clicking the Update link, the control is forwarded to the adminupdate.jsp page with the empNo Parameter.. On the adminupdate page i would want to display the data of the selected employee. But these values are not available in the request object, I don't want to call another servlet passing the empNo and fetching the values of the employee as the values were already available in the previous page, so I would like to know what would be the best approach in getting the same values in the admin update page.

Thanks
John
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37230
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
It looks like you are passing the values as parameters. You could use request.getParameter() to get the values on the second page.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

I've spent a little time thinking about your question and my conclusion is that the best approach is to rewrite the whole thing using JSTL, MVC2, XHTML, CSS and other stories.

Back in the real world the quickest and dirtiest approach is to include your other employee details, along with empNo, in the URL parameters to adminupdate.jsp. That should at least get you over this particular hurdle. As Jeanne says you can then access them via request.getParameter() in the target page.

Perhaps a happy medium would be access your pages via a controller servlet in which you would add a bean containing the selected employee details to the request context (request.setAttribute). That would be a much better design than you have at present.

Back to quick and dirty again, if your ResultSet has session scope and is scrollable, you might also want to consider including the record number in the adminupdate.jsp URL and then using it to get the corresponding employee details that way.

Anyway, I hope that gives you some ideas.

Jules
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37230
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True. While we are discussing best practices, it is good to avoid having logic - especially JDBC code - in a JSP.
 
John Vergis
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne and Julian
I am not passing all the parmeters in the URL while doing an update., I am setting only the empNo in the URL, what i had thought was on clicking on the update link, instead of calling the jsp, forward it to the servlet with the empNo and then from the servlet set all these values in the request object and do a forward to the jsp, but I wanted to avoid these, bcoz all these values were already present when the user clicks on the Update Link, the only concern is how to get those values in the next page without sending all the parameters as part of the URL.
May be this needs a shift in the design...
Thanks again
John
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!