Today, I just got into touch with some questions about the form Action attributes and method attributes when using JSP and Servlet for a simple login;
What I encountered was a problem when the form was submitted to servelet for processing:
(1) <form name = "login" Action = "①? "Method =" ②? ">
// Form Content
Username: <input type = "text" name = "username"> <br>
Password: <input type = "password" name = "PWD"> <br>
<Input type = "Submit">
</Form>
(2) the corresponding servlet class for processing user requests is helloservlet. Java;
(3) configure the Web. xml file:
<Servlet>
<Servlet-Name> ③ servlet </servlet-Name>
<Servlet-class>/helloservlet </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> ③ servlet </servlet-Name>
<URL-pattern>/① welcome </url-pattern>
</Servlet-mapping>
In login. jsp, it should be:
<Form action = "① welcome" method = "②? ">
In this case, the URL of login. jsp is http: // localhost: 8080/JSP/login. jsp.
The helloservlet. Java URL is http: // localhost: 8080/JSP/welcome.
Available values in helloservlet
String name = "";
String Pwd = "";
Name = Req. getparameter ("username ");
Pwd = Req. getparameter ("PWD ");
Note: Web. in XML, ③ the two servlet-names must be consistent; In ①, URL-pattern must be consistent with the action attribute value in form; ③ The method is the get method by default, however, this method exposes the value to the browser, so the POST method is generally used to hide the value content;