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
This article example shares the specific code of ...
Introduction The Docker-Compose project is an off...
Recently, an online security scan found a vulnera...
Shorthand properties are used to assign values ...
There is a simple CSS method to realize the pop-u...
Preface Let’s take a look at the final effect fir...
Preface Creating shortcuts in Linux can open appl...
Table of contents 1. Basic use of css(): 1.1 Get ...
SQL finds all duplicate records in a table 1. The...
Sprite Cow download CSS Lint download Prefixr dow...
List of HTML tags mark type Name or meaning effec...
Preface You may often receive warning emails from...
1. Copy the configuration file to the user enviro...
1. Introduction to Animate.css Animate.css is a r...
Preface Before leaving get off work, the author r...