This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "POST form data from Servlet to JSP" Watch "POST form data from Servlet to JSP" New topic
Author

POST form data from Servlet to JSP

Ricardo Marques
Greenhorn

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
Greenhorn

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
Greenhorn

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
Greenhorn

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: POST form data from Servlet to JSP
 
Similar Threads
'POST'ing parameters to another JSP
Can I use repaint() on a JFrame?
IllegalStateException in JSP
Single Portlet Refresh in a Portal Page
Getting the name of the requesting page