• Post Reply Bookmark Topic Watch Topic
  • New Topic

Execute servlet from another application

 
Sajan Patel
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have one servlet in one Application.
Suppose we have this url (http://www.myurl.com/myApplication/myServlet?myAtt=myValue) for that sevrlet.

Now I want to execute that servlet from my application.

I use java.net.URL for this
new java.net.URL(aboveAddress).getContent();

and it is executing that servlet but it is throwing error also.


java.net.UnknownServiceException: no content-type
java.net.URLConnection.getContentHandler(URLConnection.java:1102)
java.net.URLConnection.getContent(URLConnection.java:617)
java.net.URL.getContent(URL.java:999)


I would like to know
Is there any other method in URL which will work like this without throwing error
OR is there any other way we can call servlet.

Thanks in Advance

Sajan Patel
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your servlet set the content type? If not, you might want to fix that. Also, read the javadoc for URLConnection.getContent().
 
Sajan Patel
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually That servlet dont need to send anything back. I just need to call it and pass one number and then it will move one file as per that number.

I use new URL(webURL).getContent() method to call that servlet (I know I am not using proper way but it is working fine except throwing error) not for get content of that servlet back.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I know I am not using proper way but it is working fine except throwing error)


So I guess it is not working fine then :-) If you want to use getContent(), you'll have to do it this way. Just set the content type to something the URL class can handle, and return a short reply. That could also serve to indicate errors in case your server operation fails.
[ July 20, 2005: Message edited by: Ulf Dittmer ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!