This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Passing parameters to URLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing parameters to URLConnection" Watch "Passing parameters to URLConnection" New topic
Author

Passing parameters to URLConnection

Ashutosh Shinde
Ranch Hand

Joined: Jun 07, 2001
Posts: 42
Hello All,
I am establishing a connection between a JSP and a Servlet which are on 2 different web servers. The JSP invokes the Servlet using the URLConnection. Is there some way by which a parameter can be passed between these two components. I do not want to pass a paramter as a Object over an ObjectOutputStream because the current flow requires me to pass an existing object on the stream. Is there some method in URLConnection which i may have missed?
Any suggestions ?!?
Regards,
Ashutosh S
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12936
    
    5
If you are addressing the other servlet with "http://..." then what you really get is a java.net.HttpURLConnection. With that you can use addRequestProperty to add your own header to the request. This could be used to pass some simple properties - of course the other servlet would have to know to look for that header.
Bill
Ashutosh Shinde
Ranch Hand

Joined: Jun 07, 2001
Posts: 42
Hello ,
Thanks William!
I am posting the code here so that anyone having the same problem can use it for reference -
JSP Code-
URL url = new URL("http://192.x.x.x:yyyy/myServlet");
HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
httpConn.setRequestProperty("action","save");

Servlet Code-
String headerData = request.getHeader("action");
Output Obtained - "save"
Regards,
Ashutosh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing parameters to URLConnection