Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Use link to forward Session entries instead of Request Dispatcher

Thread view: 
francan00@yahoo.com - 13 Sep 2007 01:57 GMT
I have objects that I pass from a Servlet to JSP using
RequestDispatcher type. Now, I was wondering if I can do the same with
a link but not sure how I do that:

Servlet called MyServlet.java (or MyServlet in web.xml mapping):

String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String city= request.getParameter("city");
String state= request.getParameter("state");
.....
HttpSession session = request.getSession();
session.setAttribute("firstname", firstname);
session.setAttribute("lastname", lastname);
session.setAttribute("city", city);
session.setAttribute("state", state);
RequestDispatcher dispatcher = getServletContex
().getRequestDispatcher("start.jsp");
dispatcher.forward(request, response);
...

The above servlet automatically goes to the JSP and shows the
firstname,lastname, city and state values that were submitted from a
form. What is the equivalent of the RequestDispatcher where I can put
a link instead so the user can click on the link and that will take
them to the JSP with the session values:

This is not working because takes to a null error page:

...
response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
                                       "Transitional//EN\">\n" +
               "<HTML>\n" +
               "<HEAD><TITLE>Hello WWW</TITLE></HEAD>\n" +
               "<BODY>\n" +
               "<p><a href="MyServlet">Link to JSP</a></p>\n" +
               "</BODY></HTML>");
.....

Please advise.
Manish Pandit - 13 Sep 2007 02:08 GMT
On Sep 12, 5:57 pm, franca...@yahoo.com wrote:
> I have objects that I pass from a Servlet to JSP using
> RequestDispatcher type. Now, I was wondering if I can do the same with
[quoted text clipped - 38 lines]
>
> Please advise.

IMO you do not need a servlet for this task. You can submit the form
directly to the JSP.

<form name="myform" action="/start.jsp">
<input type="text" name="firstname"...../>
..
..
</form>

In start.jsp, use EL to get the values

<p> First Name: ${param.firstname} </p>
<p> Last Name: ${param.lastname} </p>
..
..

-cheers,
Manish
francan00@yahoo.com - 14 Sep 2007 00:55 GMT
> On Sep 12, 5:57 pm, franca...@yahoo.com wrote:
>
[quoted text clipped - 61 lines]
>
> - Show quoted text -

Thanks,  I need the Servlet as a Controller for other stuff and I dont
have EL or JSTL in my Tomcat 4.1.27.  Please advise.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.