Action path in Form

Source: Internet
Author: User
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;



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.