为什么JSP不支持表单上的“放置"方法?有什么方法可以在jsp表单上使用put方法吗? [英] Why JSP is not supporting 'put' method on form? Is there any way to use put method on jsp form?

查看:172
本文介绍了为什么JSP不支持表单上的“放置"方法?有什么方法可以在jsp表单上使用put方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以JSP形式实现 put 方法,但似乎支持该方法,其背后的原因是什么? 如果我使用HTML而不是JSP并调用实现为接受放置请求的servlet,那么它将按预期工作.但是相同的代码在JSP上不起作用.

I am trying to implement put method in JSP form, but seems like it is supported, what is the reason behind it ? Where if i am using HTML instead of JSP and calling a servlet implemented to accept put request, then it is working as expected. but same code is not working on JSP.

正在运行"index.html">>>

  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>PUT Method Test</title>
    </head>
   <body>
   <form enctype="multipart/form-data" **method="PUT"**
     action="RequestTester">
    <input type="file" size="20" name="FileToUpload"
     value="Select File">
    <input type="submit" name="UploadFile" value="Upload">
    <input type="reset" value="Reset">
    </form>
     </body>
   </html>

无法正常工作的HTML的示例"index.jsp">>>

    <form enctype="multipart/form-data" **method="PUT"**
           action="RequestTester">
        <input type="file" size="20" name="FileToUpload"
          value="Select File">
         <input type="submit" name="UploadFile" value="Upload">
        <input type="reset" value="Reset">
     </form>

MyServlet类>>

public class RequestTester extends HttpServlet {

private static final long serialVersionUID = 1L;


public PostRequestTester() {
    super();
}


protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException          {
    System.out.println("GET REQUEST STARTED..");
}

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    System.out.println("POST REQUEST STARTED..");


}

protected void doPut(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    System.out.println("PUT REQUEST STARTED..");

}

}

推荐答案

这不是JSP的限制.通常,PUT方法根本不打算提交表单.它有不同的目的.在任何平台上,您都可以在获取发布之间进行选择,以提交表单.

This is not the limitation of JSP. The PUT method is generally not intended for submitting forms at all; it has a different purpose. On any platform, you may choose between get and post for submitting forms.

这篇关于为什么JSP不支持表单上的“放置"方法?有什么方法可以在jsp表单上使用put方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆