其他分享
首页 > 其他分享> > Tomcat初学时遇到的问题

Tomcat初学时遇到的问题

作者:互联网

一、IDEA控制台乱码

1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
1catalina.org.apache.juli.AsyncFileHandler.encoding = GBK

2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
2localhost.org.apache.juli.AsyncFileHandler.encoding = GBK

3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
3manager.org.apache.juli.AsyncFileHandler.encoding = GBK

4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
4host-manager.org.apache.juli.AsyncFileHandler.encoding = GBK

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
java.util.logging.ConsoleHandler.encoding = GBK

二、未知版本字符串 [4.0]警告

警告 [RMI TCP Connection(5)-127.0.0.1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion 未知版本字符串 [4.0]。将使用默认版本。

  1. 手动修改web.xml文件
<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_3_1.xsd"
         version="3.1">

注意xsi:schemaLocation一行最后web-app_4_0.xsd别忘了改
2. 提升Tomcat至9版本

三、相对路径失效

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String studentName = request.getParameter("StudentName");
        String studentAge = request.getParameter("StudentAge");
        String studentScore = request.getParameter("StudentScore");
        Student student = new Student(studentName,Integer.parseInt(studentAge),Integer.parseInt(studentScore));
        BufferedWriter bw = new BufferedWriter(new FileWriter("students.txt",true));

此时的生成的students.txt文件会跑到Tomcat文件夹的bin目录下
在JavaWeb工程中不用相对路径都用绝对路径

ServletContext context = getServletContext();
        String realPath = context.getRealPath("/");
        BufferedWriter bw = new BufferedWriter(new FileWriter(realPath+"\\students.txt",true));

生成的students.txt文件会保存在项目目录下如:
Servlet-Demo01\out\artifacts\Servlet_Demo01_war_exploded\

标签:Tomcat,遇到,juli,GBK,manager,初学,apache,org,AsyncFileHandler
来源: https://blog.csdn.net/Spring_ChenMy/article/details/117199626