Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing parameters to URLConnection

 
Ashutosh Shinde
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic