Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirecting a form in jsp

 
Michael J. Makunas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure there's a trivial solution to this but for some reason I can't figure it out.

I have an HTML form on my site that is submited to another site (i.e., ACTION="a url on someone else's site"). I need to capture some of the form data before sending it off to the other site. I tried creating a jsp that grabs the parameters I need and then calls response.sendRedirect() but in doing that I seem to lose all of the form parameters. Any ideas on how to do this?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a Servlet that your form submits to and in your servlet grab what you need, then forward the request from there.

response.sendRedirect()...

Um, yeah. That's what it is supposed to do. When you do a redirect, you are creating a new request. You have to forward a request to keep it's context.
[ July 23, 2004: Message edited by: Gregg Bolinger ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Low tech approach: in your servlet/JSP process your params as appropriate, then construct an HTML form element with all the parameters as hidden controls. In an onload handler, submit the form.

Hi tech approach: use HttpConnection to establish your own connection to the other server and perform a post operation.
[ July 23, 2004: Message edited by: Bear Bibeault ]
 
Michael J. Makunas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Low tech approach: in your servlet/JSP process your params as appropriate, then construct an HTML form element with all the parameters as hidden controls. In an onload handler, submit the form.

Hi tech approach: use HttpConnection to establish your own connection to the other server and perform a post operation.

[ July 23, 2004: Message edited by: Bear Bibeault ]


Low tech: Thought about that.
High tech: Am I right in assuming you mean org.apache.commons.httpclient.HttpConnection? This sounds like the way to go.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic