Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

How do I submit an HTML form, which is a String in my Servlet....need to post it from my Servlet?

I have a Servlet in a WebSphere Web Container.  I need to submit a page to another application in another Web Container running in WebLogic.

What I've done thus far is use the doGet() in my Servlet to retrieve some needed values from my login page out of the request object.  Then I opened a URLConnection to the other application and read in a form from their site.  

Now I have the entire HTML form stored in my Servlet as a String,
from the "<!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.0 Transitional//EN"><html>"
to the </html>.  

Their form does a POST and the ACTION passes in something like

FORM NAME="LoginForm" METHOD="POST" ACTION="VP;jsessionid=2CqLONoS8guu78brXG33q2JsJL8IGK3cKF0w9lU1k47F2UUG28e5!-1627733873!152169157!7002!7022">

The jsessionid was established with I read the page from the URLConnection.  The form is pretty simple,
a couple of input text fields and serveral hidden field.

So I need to submit this form.  It performs a login on the other application.

I tried a resp.sendRedirect( "http://server:7002/VP;jsessionid=2Dle1E45iqBrIziJcPWtE3ChsfzYphQiLg3QWePuHI5zUtqHCPCF!-1627733873!152169157!7002!7022" )

But this displays an error on their page.  Don't this this is really submitting that form String in my Servlet.  I don't believe forwards will work because I think you need to forward to a URL in the same Web Container.  Same goes for includes, they more or less get bounced back to my doGet().

I think I can open another URLConnection or Socket back to the server, but not sure how to POST this and keep it from coming back to my doGet().

Any help would be greatly, greatly appreciated.
0
jred
Asked:
jred
1 Solution
 
sfotexCommented:
I think you want to create a new  http connection to the server in your servlet and submit your info,
You probally don't  want to do a redirect b/c that
will divert the user to the other site, where it sounds like you want to signal the other server of a login...
0
 
jredAuthor Commented:
Yes, I want the other server to do the login and return me the next page, so my Servlet more or less becomes the middle man.

How would I create a new HTTP Connection and submit the login form?
0
 
jredAuthor Commented:
Yes, I want the other server to do the login and return me the next page, so my Servlet more or less becomes the middle man.

How would I create a new HTTP Connection and submit the login form?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jerelwCommented:
1.simulate a post e.g. - http://www.javaworld.com/javatips/jw-javatip34_p.html)

2.read in your InputStream
3.display your scraped page
0
 
victorliCommented:
The "<Form name=... method=... >... </Form>" kind stuff is only run in client side which means in browesr. They have no place in your server component. Like Java applet or javascript, what can you do with them in your servlet or jsp?

Try this:
(1) Check the url and login parameters of another web site. Suppose their form action is "http://anotherside/login.jsp
the login name prameter key is "thatName" and password key is "thatPswd". It is easy to get the above information.
(2) in your servlet, forget about URLConnection, try the following:

String userName = request.getParameter("thisName");
String pswd = request.getParameter("thisPassword");

response.sendRedirect("http://anotherside/login.jsp?thatName="+userName+"&thatPswd="+pswd);  
0
 
victorliCommented:
What I mean "the form element has no place in your server component" is you can not submit a form in server side. Of course you can embed them in your servlet and send them to client side to submit.
0
 
CleanupPingCommented:
jred:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
jimmackCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ - No refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0
 
YensidModCommented:
This question is PAQed  and no points refunded (of 100).

YensidMod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now