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
Starting from Elasticsearch 6.8, free users are a...
1. Add a new user Only allow local IP access crea...
When I was looking at some CSS3 animation source ...
We often need to control the hidden, transparent ...
This is what happened. Today I was playing with G...
Solution to MySQLSyntaxErrorException when connec...
1. Go to the official website www.mysql.com and s...
Scenario: When page A opens page B, after operati...
MySQL needs to be upgraded to version 5.5.3 or ab...
<template> <div class="app-containe...
This article mainly introduces the installation/st...
In actual projects, there are relationships betwe...
Table of contents Preface Environment Preparation...
This article shares the specific code for JavaScr...
Table of contents Preface advantage: shortcoming:...