For the basic configuration of the servlet in the Web. xml file in the Javaweb project there are some small records written here, and do reference, with new and timely updates

Source: Internet
Author: User

For the basic configuration of the servlet in the Web. xml file in the Javaweb project there are some small records written here, and do reference, with new and timely updates

<?XML version= "1.0" encoding= "UTF-8"?><Web-app>    <!--when creating a Web project, if the system is automatically generated, there will be a bunch of configuration information, because it does not affect the overall situation, here is not listed -  <!--process: When using/login in the Web page, found not the Web page, then will find the corresponding name in XML, defined by Url-pattern, find the corresponding servlet-name, and then find the corresponding Servlet-clas s, complete loading of the class and creation of the object -  <!--How do I configure a servlet to let the Web container recognize it?  -  <!--write the servlet tag, which contains Servlet-name,servlet-class -  <servlet>      <!--Servlet-name just gives the servlet a name that is used in Web. XML -      <Servlet-name>This</Servlet-name>      <!--Servlet-class Write the Java file to correspond to the servlet, with the fully qualified name (automatically reflected) package name + class name -      <Servlet-class>Com.lovo.myweb_1.servlet. Loginservlet</Servlet-class>  </servlet>    <!--mapping servlet -  <servlet-mapping>      <!--find the name from the servlet tag -      <Servlet-name>This</Servlet-name>      <!--bind the path and name -      <!--Http://localhost:8080/myweb-1/login -      <Url-pattern>/login</Url-pattern>  </servlet-mapping>  </Web-app>

Some of the issues to note here are:

1, the full-qualified name of the writing: for the package name + class name

2, the path of writing: there are several formats

First:/b exact pattern matching

Second type: *.BBB extension matches

The third type:/smallclass/add path matching

Fourth:/default Road Strength match--Select default path can be used to set back a fixed page

This is only the format, if not written, the server will not be recognized when booting, error, This login is generated under the Web project main file, when the form form submitted to jump to this page can use relative path and absolute path, we recommend using absolute path

Deployed on the server, the workspace is WebApps this folder, http://localhost:8080/is pointing to the next level of this folder

Absolute path: The path name is written in full,/project folder/login, not due to changes in the HTML file;

Relative path: in.. /.. /In a way relative to the HTML file, when the location of the HTML file changes, you need to rewrite the change of writing;

Submission path in the form

    <!--/login indicates that it is from the first level of the Myweb-1 directory to find content -    <formMethod= "Get"Action= "/myweb-1/login">        <P>            <inputtype= "text"name= "UserName"placeholder= "Please enter account">        </P>        <P>            <inputtype= "Password"name= "pwd"placeholder= "Please enter password">        </P>        <inputtype= "Submit"value= "Login">        <inputtype= "Reset"value= "Reset">    </form>

Action= "" In the form above, that is, to write this form click submit after the page should jump, pay special attention to the writing path is correct, or 404 waiting for you!!!

For the basic configuration of the servlet in the Web. xml file in the Javaweb project there are some small records written here, and do reference, with new and timely updates

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.