what values can a JSP form “action” take?

前端 未结 1 1251
無奈伤痛
無奈伤痛 2021-01-14 20:26

What can a JSP form action be? I have a Login.jsp page for the user to end the details. Can i give the servlet class in the form action?

here is the the servlet cod

相关标签:
1条回答
  • 2021-01-14 20:54

    As per the specs , it can take any valid URI

    This attribute specifies a form processing agent. User agent behavior for a value other than an HTTP URI is undefined.

    Can i give the servlet class in the form action ?

    Yes if the servlet class name resolves to a valid URL mapped in the web.xml or else you will encounter a 404 .

    Let us consider your JSP is at the root of the application, then

    <FORM action="someServletName" method="post">
    

    Now this will be resolved as protocol://servername:port/context/someServletName .Now somewhere you should have a mapping for /someServletName , either in web.xml or through annotation to a Servlet or JSP.

    <servlet>
         <servlet-name>someServletName</servlet-name>
         <servlet-path>packageName.servletName</servlet-path>
    </servlet>
    <servlet-mapping>
         <servlet-name>someServletName</servlet-name>
         <url-pattern>/someServletName</url-pattern>
    </servlet-mapping>
    
    0 讨论(0)
提交回复
热议问题