The 404 problem occurs in the Tomcat test. The problems are as follows: HTTP Status 404 - Not Found Type Status Report Message The requested resource [/chapter06/IndexServlet] is not available Description The origin server was unable to find a representation for the target resource or is unwilling to expose an existing representation for the resource. The problem is that the browser cannot directly access the Java file. Solution to the problem 1. This problem occurs when submitting a form <form name = "reg" action="/login" method="post"> <meta charset="UTF-8"> Account: <input type="text" name="username"/><br> Password: <input type="password" name="passward"/><br> <input type="submit" value="Submit" id="bt"> </form> The reference in 2. Accessing the Java file in the src path reports an error You need to configure routing for the target Java file. There are two ways to configure it: (This is just a brief description. If you want to know more details, click here) (1): Configuration based on annotations Only applicable to Tomcat 3 and above (I think it is 3, I can't remember) package cn.itcast.chapter06.session.example; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/logout") //Here is the routing configuration public class LogoutServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.getSession().removeAttribute("user"); resp.sendRedirect("/wel"); } @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } } **@WebServlet("/logout") //Here is the routing configuration, which is also the most commonly used method. **The quotation marks are for routing (2) Configuration based on XML file Click to open the web.xml file, then modify the web.xml code and add a mapping before < /app > <servlet> <servlet-name>hello</servlet-name> <servlet-class>com.southwind.servlet.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/demo2</url-pattern> </servlet-mapping> Map demo2 and hello. You can map HelloServlet by directly accessing demo2 in the browser. This is the end of this article on how to solve the problem of 404 error in Tomcat. For more information about 404 error in Tomcat, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Using js to achieve waterfall effect
>>: Setting the engine MyISAM/InnoDB when creating a data table in MySQL
As shown below: SELECT count(DISTINCT(a.rect_id))...
Two problems that are easy to encounter when inst...
1. Dashed box when cancel button is pressed <br...
Find the problem Today I encountered a problem of...
This article example shares the specific code of ...
Table of contents 0. What is Module 1.Module load...
Table of contents 1. Container lifecycle manageme...
Click here to return to the 123WORDPRESS.COM HTML ...
Mixins provide distributed reusable functionality...
Achieve results Implementation Code html <div ...
A brief introduction to protobuf Protobuf is Goog...
What is serdel userdel is a low-level tool for de...
This article mainly introduces how to implement a...
Create a project directory mkdir php Create the f...
background In the early stages of learning Japane...