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
My97DatePicker is a very flexible and easy-to-use...
This article shares the specific code of Vue+echa...
1. Install Zabbix Agent to monitor the local mach...
Open the folder C:\web\mysql-8.0.11 that you just...
This article shares the specific code of JavaScri...
I just bought an Alibaba Cloud host and couldn’t ...
Because frameset and body are on the same level, y...
Preface Since the most important data structure i...
Today, after the game was restarted, I found that...
When making a web page, you sometimes use a dividi...
Table of contents 1. Static implementation method...
Structure related tags ---------------------------...
The solution to the transparent font problem after...
There are two ways to configure multiple projects...
Look at the solution first #------------The probl...