HttpServlet:未调用 doPut
我有一个 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
}
}
使用 GET 一切都很好。调用方法doGet
。但是从我的 iPhone 应用程序执行 put 时,没有调用 doPut
方法。服务器上没有任何反应,我在日志文件中看不到任何内容。那么出了什么问题呢? Tomcat 有 PUT 限制吗? 我该如何调试这个?在 iOS 设备上,我使用一个库,我可以告诉它应该使用 PUT,所以它应该可以工作,因为它是一个非常常见的框架。
有人有想法吗?
最好的问候蒂姆。
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 idea?
Best Regards Tim.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 wireshark 跟踪数据包以确保您确实收到 PUT 请求。
或者类似地为tomcat设置单独的访问日志(已经在默认配置文件中,但我相信被注释掉了)看看会发生什么。
如果您在您最喜欢的文本编辑器中打开 tomcat 目录中的文件 conf/server.xml 那么您会在接近尾声时发现:
如果删除评论标记,所有访问都将记录到 logs/localhost_access_log 中。
例如:
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 :
if you remove the comment tokens all access will be logged to logs/localhost_access_log.
e.g. :
doPut() 是一个有效的方法,但您更有可能想要执行 doPost()。
HTTP 定义了 GET、POST 和 PUT(等等),但一般来说 GET 用于访问页面,而 POST 用于发布数据。
您可以在以下位置获取有关这些动词定义的更多详细信息:
http://www. w3.org/Protocols/rfc2616/rfc2616-sec9.html
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