注意事项

1. Maven

  1. 在类路径(源代码目录)中写的配置文件无法被导出或者生效

    解决方法有两种:

    1. 配置文件放到resources(资源目录)下。
    2. 修改pom.xml文件。
    <!--在pom.xml中,在build中配置resources,来防止我们资源导出失败的问题-->
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
    

    在编译的时候,源代码目录和resources会被编译到classpath目录中。对应Java web的目录为:webapp/WEB-INF/classes

  2. 子模块无法引用父模块的依赖

    子模块的pom.xml没有添加父模块的引用,需添加

    <parent>
      <artifactId>javaweb-maven</artifactId>
      <groupId>com.gs</groupId>
      <version>1.0-SNAPSHOT</version>
    </parent>
    

2. Tomcat

  1. web.xml的版本务必与Tomcat支持的最新版本保持对应,减少发生不必要的问题。Maven自动创建的版本为2.3,而Tomcat10中的最新版本为5.0.

    一定要更换tomcat兼容的。亲测Tomcat10下2.3版本的web.xml无法解析EL表达式。

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
                          https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
             version="5.0"
             metadata-complete="true">
    
    </web-app>
    
  2. Tomcat 10下继承Servlet后打开网页提示找不到Servlet

    Tomcat 10下已经不是javax的包,而是jakarta

    如果原项目中有依赖javax.servlet,需要将该依赖同步更新为jakarta.servlet。并重新导包。

    或者降级Tomcat版本。

  3. Tomcat 10 使用jakarta包。

    <dependencies>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>jakarta.servlet.jsp</groupId>
        <artifactId>jakarta.servlet.jsp-api</artifactId>
        <version>3.0.0</version>
      </dependency>
      <dependency>
        <groupId>jakarta.servlet</groupId>
        <artifactId>jakarta.servlet-api</artifactId>
        <version>5.0.0</version>
      </dependency>
      <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.25</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.glassfish.web/jakarta.servlet.jsp.jstl -->
      <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jakarta.servlet.jsp.jstl</artifactId>
        <version>2.0.0</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-spec -->
      <dependency>
        <groupId>org.apache.taglibs</groupId>
        <artifactId>taglibs-standard-spec</artifactId>
        <version>1.2.5</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl -->
      <dependency>
        <groupId>org.apache.taglibs</groupId>
        <artifactId>taglibs-standard-impl</artifactId>
        <version>1.2.5</version>
        <scope>runtime</scope>
      </dependency>
      <dependency>
        <groupId>jakarta.servlet.jsp.jstl</groupId>
        <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
        <version>2.0.0</version>
      </dependency>
      <dependency>
        <groupId>jakarta.el</groupId>
        <artifactId>jakarta.el-api</artifactId>
        <version>4.0.0</version>
      </dependency>
    </dependencies>
    

3. 其他

  1. 重定向需要加上项目路径,而请求转发不用。
Copyright © rootwhois.cn 2021-2022 all right reserved,powered by GitbookFile Modify: 2023-03-05 10:55:52

results matching ""

    No results matching ""