Java HttpServlet:未调用doPut

Java HttpServlet:未调用doPut,java,iphone,http,servlets,put,Java,Iphone,Http,Servlets,Put,我有一个Tomcat应用服务器和以下Java源代码: public class MyServlet extends HttpServlet { public MyServlet() {} protected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { // ... PUT code } pro

我有一个Tomcat应用服务器和以下Java源代码:

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
    }
}
有了你,一切都很好。调用方法
doGet
。但是,在我的iPhone应用程序中,执行put时不会调用
doPut
方法。服务器上什么也没发生,我在日志文件中什么也没看到。那怎么了?对Tomcat有任何限制吗? 我如何调试这个?在iOS设备上,我使用了一个库,我知道应该使用PUT,所以它应该可以工作,因为它是一个非常常见的框架

有人有主意吗

向Tim致意。

用于跟踪数据包,以确保您实际收到PUT请求

或者类似地(它已经在默认配置文件中,但我相信已经注释掉了),以查看即将出现的内容

如果您在favorit文本编辑器中打开tomcat目录中的文件conf/server.xml,那么您将在末尾找到:

    <!-- 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"/>
    -->

如果删除注释标记,所有访问都将记录到日志/localhost\u access\u 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()是一个有效的方法,但您更可能希望执行doPost()

HTTP定义GET、POST和PUT(以及其他),但一般来说GET用于访问页面,而POST用于发布数据

有关这些动词定义的更多详细信息,请访问:


如何使用单独的访问日志来完成此操作?我添加了一个到tomcat文档的链接。它包括启用AccessLogValve。非常有用的工具。非常有用,我发现了问题。它没有发送到服务器:-(但只有在您的帮助下,我才找到了问题。这是一个更可能的解释,除非OP通过RESTful界面上载文件。当然可能需要PUT而不是POST,但可能不太可能。iOS设备上使用的客户端库是什么?