Because the version I used when I was learning was relatively new, and the tutorials on the Internet were all old versions, many problems occurred. The following is a summary to help other beginners avoid pitfalls. 1: The project name can be named arbitrarily 2: Check Web Application and click OK 3: 4: Then select Dependencies, click the + sign below, select jars or dirxxxxxxxx, select the lib directory you just created, and if you want to select the directory to use, select jar direxxxxxxx, check it, click apply, OK 5: 6: 7: 8: import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; @WebServlet(name = "login") public class Login extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML>"); out.println("<HTML>"); out.println(" <HEAD><TITLE>login</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" this is login page"); out.print(this.getClass()); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML>"); out.println("<HTML>"); out.println(" <HEAD><TITLE>login</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" this is login page"); out.print(this.getClass()); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } } Then modify the web.xml file as follows:
-name can be any name as long as the upper and lower parts are consistent. servlet-class should be the same as the class name. url-pattern should be the same as xxxx in @WebServlet(name="xxxx") in java class, where xxxx is the path. This is the end of this article about the pitfalls of the newer version of IDEA2021 tomcat10 servlet. For more related idea2021 tomcat servlet content, 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:
|
<<: Example code for hiding element scrollbars using CSS
>>: Optimizing JavaScript and CSS to improve website performance
Download the redis image docker pull yyyyttttwwww...
In HTML pages, we sometimes need to automatically ...
1. After installing the Windows version of Docker...
Table of contents 1. Prepare the springboot proje...
Cluster Deployment Overview 172.22.12.20 172.22.1...
Table of contents 1. Download 2. Installation 3. ...
1. Effect display An astronaut watch face written...
I am currently learning about Redis and container...
To debug js code, you need to write debugger in t...
Table of contents 1. Download 2. Installation and...
My page today also had garbled characters, so I s...
This article shares the specific code of JS to ac...
This article example shares the specific code for...
I finally finished the project at hand, and the m...
(1) Server configuration: [root@localhost ~]# cd ...