File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes  Problem regarding URLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark " Problem regarding URLConnection" Watch " Problem regarding URLConnection" New topic
Author

Problem regarding URLConnection

Atul Prabhu
Ranch Hand

Joined: Dec 17, 2002
Posts: 60
Hi friends,

I am using URLConnection to connect to third party page. The code is as follows


This form submits to the specified url in the action
My problem is I want to access the values of this form after it submits, in the same java file.
Right now I am parsing the form in the while loop and retrieving the values.(that is bad approach)

I have a solution is that to shift this code into a servlet and mention action="http://ourhomepage.com/SomeServlet", I think this would solve the problem.
But if anyone knows a better approach for getting the data ... please do share it with me.

Is it possible to communicate with same connection multiple times?



Regards
Atul
Rovas Kram
Ranch Hand

Joined: Aug 08, 2003
Posts: 135
If I understand you correctly, you are calling a third party web server and it's returning html. Of course this html must be parsed. Maybe you can use a XML parser since XML is supposed to be super-set of html. Also, can the third party create a web service for you?
Atul Prabhu
Ranch Hand

Joined: Dec 17, 2002
Posts: 60
Hi Rovas,

Yes I am calling a third party page which submits it to a "specified url".I want to access the parameters that are hidden in the form.Parsing the form is not a good idea according to me.What I want is to access parameters in terms of request.So my question is can I get the parameters in the request object?

Actually I can get the parameters in the request object,i.e. in the "specified url". But can I get the response in the same java file given above ?
Rovas Kram
Ranch Hand

Joined: Aug 08, 2003
Posts: 135
Hi Atul,

Using the URLConnnection, the output is an Outputstream which returns the html form. There is no response object so the html must be parsed. If you actually submit the form(i.e. from a browser), the parameters will be parsed by the server and put into a request object. But there is no 'request' object on the client side. Rememeber that HTML is a text based protocol and it must be parsed. There maybe a class out there that can parse a html document and then provide 'get' methods for accessing the default parameters and hiddenvalues of a form but I don't know of one.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem regarding URLConnection