File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes POST form data from Servlet to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "POST form data from Servlet to JSP" Watch "POST form data from Servlet to JSP" New topic

POST form data from Servlet to JSP

Ricardo Marques

Joined: May 08, 2002
Posts: 27
Hi everybody,
I have a JSP page (let's call it P1) which has a form. This form invokes a servlet (S1), which checks if the current session is valid and authenticates the user to the system, and then redirects to another page (P2), which depends on P1.
What I wanted to do was to get the field values from the FORM on P1, which uses the method POST and then send these values on to P2, whatever it is. I do not want to pass the value encoded in the URL (same as using GET in FORMS), and I cannot pass the values as sessions attributes either.
Any ideas on how I can accomplish this? Yet another thing I can't do is to have the servlet code in each P2 that depends on P1.
I appreciate any ideas. Thank you.

Sun Certified Programmer for the Java 2 Platform 1.4<p>If I can create, I will make mistakes. If I can learn with them, it must be some kind of art.
George Carlson

Joined: Aug 24, 2000
Posts: 15
Do you have to post to a servlet? My reason for asking is because it would be very easy to post to another jsp page, which calls that servlet's methods (you can even call the doGet method) or another bean to verify the data. From there, you do a <jsp:forward> to another page. Keeps the same request method so you don't lose anything.
Ricardo Marques

Joined: May 08, 2002
Posts: 27
Thank you George.
Unfortunatelly I really need to post to a servlet. The system analysis requires so.
The servlet actually does more than I stated, but It didn't seem important to refer.
Thanks anyway.
Junaid Bhatra
Ranch Hand

Joined: Jun 27, 2000
Posts: 213
Maybe I'm missing something here, but if you want to keep the original request data, why don't you do a RequestDispatcher.forward() from your servlet instead of a redirect()? The problem with doing a redirect is that the original request (and along with it any request parameters and attributes) is discarded, and the client makes a new request to the re-directed page. So forward() would still allow you to keep the original request and any parameters associated with it.
Ricardo Marques

Joined: May 08, 2002
Posts: 27
Thank you Junaid.
I tried that out yesterday at the end of the day and it worked just fine.
It seems that the version of the documentation installed in my working machine wasn't up to date. So it just didn't show that method...
Thanks for all the help everybody.
I agree. Here's the link:
subject: POST form data from Servlet to JSP
It's not a secret anymore!