Why JSP is not supporting 'put' method on form? Is there any way to use put method on jsp form? [duplicate]

て烟熏妆下的殇ゞ 提交于 2020-05-13 21:13:52

问题


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.

Example of HTML Which is working "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>

Example of HTML Which is not working "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 class>>

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..");

}

}


回答1:


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.



来源:https://stackoverflow.com/questions/21130950/why-jsp-is-not-supporting-put-method-on-form-is-there-any-way-to-use-put-meth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!