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