Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

POST form data from Servlet to JSP

 
Ricardo Marques
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
George Carlson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic