HttpServlet: doPut is not called
I have a Tomcat application server and this Java source code:
public class MyServlet extends HttpServlet {
public MyServlet() {}
protected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
// ... PUT code
}
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
// ... GET code
}
}
With GET everything is fine. The method doGet
is called. But from my iPhone app doing a put the doPut
method is not called. Nothing happens on the server, I see nothing in the log files. So what´s wrong? Are there any PUT limitations on Tomcat?
How can I debug this? On the iOS device I use a library which I can tell that PUT shall be used, so it should work, because it is a very common framework.
Does anyone have an id开发者_JAVA百科ea?
Best Regards Tim.
Use wireshark to trace the packets to make sure you actually get a PUT request.
Or similarly setup a separate access log for tomcat (it is already in the default config file, but commented out I believe) to see what is coming in.
If you open in your favorit texteditor the file conf/server.xml in the tomcat directory then you'll find near the end :
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
if you remove the comment tokens all access will be logged to logs/localhost_access_log.
e.g. :
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
doPut() is a valid method, but more likely you want to execute a doPost() instead.
HTTP defines GET, POST and PUT (amongst others), but in general GET is used for accessing pages whereas POST is used for posting data.
You can get more details on the definition of these verbs at:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
精彩评论