aspose file tools*
The moose likes JSP and the fly likes Redirecting a form in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Redirecting a form in jsp" Watch "Redirecting a form in jsp" New topic
Author

Redirecting a form in jsp

Michael J. Makunas
Ranch Hand

Joined: Mar 11, 2002
Posts: 37
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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 ]

GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael J. Makunas
Ranch Hand

Joined: Mar 11, 2002
Posts: 37
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirecting a form in jsp