?
Solved

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

Posted on 2003-03-28
9
Medium Priority
?
325 Views
Last Modified: 2013-11-24
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
Comment
Question by:jred
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 2

Expert Comment

by:sfotex
ID: 8226943
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
 

Author Comment

by:jred
ID: 8227107
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
 

Author Comment

by:jred
ID: 8227132
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 3

Expert Comment

by:jerelw
ID: 8227393
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
 
LVL 1

Expert Comment

by:victorli
ID: 8230409
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
 
LVL 1

Expert Comment

by:victorli
ID: 8230427
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
 

Expert Comment

by:CleanupPing
ID: 9058429
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9735259
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
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9784309
This question is PAQed  and no points refunded (of 100).

YensidMod
Community Support Moderator
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question