• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sending PUT,DELETE requests to HttpServlet (urgent)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to use HttpUrlConnection in a client applet to send requests to server. But my HttpServlet didn't run any of the overriden doGet(),doPost(),doPUT() or doDelete() methods. I think it didn't get the incoming bytes as an http request.
This was my code for sending requests. I could not see any problems but maybe you will.

Question:
how can i send requests to a servlet as an html form sends post and put requests. is there any other way than HttpUrlConnection.
Can anyone show me a way for this?
Thanks.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a lot that can go wrong here.
First, you should make sure that the URL is valid by opening it with a browser.
Next, if you read the documentation for URLConnection, you'll see that the way you use the class (and subclass HTTPUrlConnection) is that you manipulate the parameters, connect to the server then receive the resource. Your code connects, then attempts to manipulate the request. Not good.
Next, you aren't encoding the request parameters. Since a URL cannot contain characters that are considered control characters (spaces for one) you must encode the parameters. URLEncoder is provided for just this purpose.
Finally, you need to close your output stream. The request to the server isn't complete until you do.
Have a look at this example and see if you can get it working for you.
 
Harun Hasdal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply

The URL is valid and true and no problem with encoding i have done it in setRequestParameters() method referenced in the above code.

I could not exactly understand what you mentioned about first manipulating parameters than connecting to server but im working on it.

i closed the output stream but again saw no action on the server side.

thanks again.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic