5

I have some javascript that uses PUT requests and I'd like to be able to use request.getParameter() to read in variables. I know that Java EE does not parse stuff from PUT requests because HTML PUT was originally intended for file upload. However I am wondering if there is a way to force this behavior anyway or at a minimum how to access the parser Tomcat uses when it parses requests for POST and run it myself on the raw request string.

Thanks.

6
  • Servlets do support PUT requests through the HttpServlet#doPut. Commented Aug 8, 2014 at 16:26
  • I know, and I am getting the PUT request. The problem is that it doesn't parse the form data I send. Commented Aug 8, 2014 at 16:27
  • What's the encoding of the form? multipart/form-data or application/x-www-form-urlencoded? Commented Aug 8, 2014 at 16:47
  • The latter: Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Commented Aug 8, 2014 at 16:51
  • 1
    You should be able to retrieve the form data through HttpServlet, like mentioned by @LuiggiMendoza. Are you sure your javascript is actually sending the form data as you expect? Commented Aug 8, 2014 at 17:01

1 Answer 1

12

The solution appears to be to add the following attribute to the Connector element of server.xml:

parseBodyMethods="POST, PUT"

This tells Tomcat to treat PUT requests like POST requests with respect to parsing the body.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.