Servlet and Tomcat Avoidance Guide
- The login page cannot be displayed.
Modify conf/tomcat-users. XML and add the following two lines to the file.
<role rolename="manager-gui,admin-gui"/>
<user username="ivandu" password="drh123" roles="manager-gui,admin-gui"/>
Copy the code
- The remote host cannot log in to the management page.
Modify the application under the meta-inf/context. The XML to < Valve className = “org. Apache. Catalina. Valves. RemoteAddrValve” Allow = “127 \ \ d + \. \ d + \ \ d + | : : 1 | 0:0:0:0:0:0:1-0” / > allow the content behind, such as to 10 segment can access:
<Context antiResourceLocking="false" privileged="true" >
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="10\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(? :Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(? : \ $1)? |java\.util\.(? :Linked)? HashMap" />
</Context>
Copy the code
Add a host with a specified IP address to access the host. For example, add a host with IP address 10.1.1.2 to access the manager and host-manager applications. Make the following changes in the webapps/manager/ meta-INF /context. XML and webapps/host-manager/ meta-INF /context. XML files:
<Context antiResourceLocking="false" privileged="true" >
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="10.1.1.2 | 127 \ \ d + \. \ d + \ \ d + | : : 1 | 0:0:0:0:0:0:1-0." " />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(? :Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(? : \ $1)? |java\.util\.(? :Linked)? HashMap"/>
</Context>
Copy the code
- “Javax. servlet does not exist” is displayed during Tomcat 10 compilation and deployment.
The servlet-related package name in Tomcat 10 has been changed from Javax to Jakarta. This version of Tomcat supports a partial implementation of Java EE9, and servlets have been upgraded to 5.0. There are currently no Servlet 5.0-related repositories in The Maven repository. Version support.
- The web.xml in the Servlet project does not need to be memorized and can be copied from tomcat’s conf directory. For example tomcat9.0.46:
<! -- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You are under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</xml-app>
Copy the code
- The default IP address obtained by request.getremoteaddr () is IPv6. To convert the IP address to IPv4, Tomcat VM options need to be configured:
-Djava.net.preferIPv4Stack=true
Copy the code
- Server output UTF-8 log display garble solution, add VM options:
-Dfile.encoding=UTF-8
Copy the code