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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing parameters to URLConnection" Watch "Passing parameters to URLConnection" New topic

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 ?!?
Ashutosh S
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13027
If you are addressing the other servlet with "http://..." then what you really get is a 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.
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();

Servlet Code-
String headerData = request.getHeader("action");
Output Obtained - "save"
I agree. Here's the link:
subject: Passing parameters to URLConnection
It's not a secret anymore!