aspose file tools*
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: 12681
    
    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


Java Resources at www.wbrogden.com
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
 
Similar Threads
JSP and UrlConnection
Capture the output of a servlet after submitting the Jsp page
passing information between servlets
Check dead link with Javascript
how to post data from applet to servlet.