如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

huangapple go评论63阅读模式
英文:

How to setup Tomcat 9 server to run it on Intellij IDEA UE (macOS)

问题

我复制了这个Java项目并像往常一样设置了Tomcat 9。但是,当我启动服务器时,我收到HTTP状态404错误。

我需要更新我的Tomcat / IntelliJ IDEA的哪个部分?我正在使用macOS上的IntelliJ Ultimate,搭配Tomcat 9和10(都安装了,但使用9),我的设备是MacBook Air(M1,2020)。

以下是我的项目的一些相关截图:

  1. Tomcat服务器
    如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

  2. Tomcat部署
    如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

  3. 浏览器
    如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

  4. 项目构建
    如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

  5. pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>filter</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>5.8.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.3</version>
            <scope>compile</scope>
        </dependency>
             
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.12.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.12.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
        </plugins>
    </build>
</project>
英文:

I forked this Java Project and set up Tomcat 9 as usual. But, when I start the server running, I get HTTP Status 404.

Which part of my Tomcat / IntelliJ IDEA, do I have to update? I'm using IntelliJ Ultimate with Tomcat 9 and 10 (both installed, but using 9) on macOS - MacBook Air (M1, 2020).

Here are some relevant screenshots from my project:

  1. Tomcat Server
    如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

  2. Tomcat Deployment
    如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

  3. Browser
    如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

  4. Artifact
    如何在Intellij IDEA UE(macOS)上设置Tomcat 9服务器以运行它。

  5. pom.xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;com.example&lt;/groupId&gt;
&lt;artifactId&gt;filter&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;packaging&gt;war&lt;/packaging&gt;
&lt;properties&gt;
&lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
&lt;junit.version&gt;5.8.2&lt;/junit.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
&lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
&lt;version&gt;4.0.1&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;jstl&lt;/groupId&gt;
&lt;artifactId&gt;jstl&lt;/artifactId&gt;
&lt;version&gt;1.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
&lt;artifactId&gt;javax.servlet.jsp-api&lt;/artifactId&gt;
&lt;version&gt;2.3.3&lt;/version&gt;
&lt;scope&gt;compile&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
&lt;artifactId&gt;junit-jupiter-api&lt;/artifactId&gt;
&lt;version&gt;${junit.version}&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
&lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
&lt;version&gt;${junit.version}&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mockito&lt;/groupId&gt;
&lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
&lt;version&gt;3.12.4&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mockito&lt;/groupId&gt;
&lt;artifactId&gt;mockito-junit-jupiter&lt;/artifactId&gt;
&lt;version&gt;3.12.4&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
&lt;version&gt;3.1.0&lt;/version&gt;
&lt;/plugin&gt;
&lt;!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
&lt;version&gt;3.0.2&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.8.0&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
&lt;version&gt;2.22.1&lt;/version&gt;
&lt;configuration&gt;
&lt;includes&gt;
&lt;include&gt;**/*Test.java&lt;/include&gt;
&lt;/includes&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
&lt;version&gt;3.2.2&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-install-plugin&lt;/artifactId&gt;
&lt;version&gt;2.5.2&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt;
&lt;version&gt;2.8.2&lt;/version&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

答案1

得分: 2

在你的派生样本项目的src/main/webapp/index.jsp文件中,包含了以下部分:

&lt;jsp:forward page=&quot;/login&quot;/&gt;

实际上,你已经成功访问了首页,并且它会重定向到项目中不存在的/login页面,因此会出现404错误。

但是你的项目中有一个src/main/webapp/login.jsp文件,所以你可以访问http://localhost:8080/xxxx/login.jsp

如果你将&lt;jsp:forward page=&quot;/login&quot;/&gt;更改为&lt;jsp:forward page=&quot;/login.jsp&quot;/&gt;,也会有帮助。

英文:

In your forked sample project's src/main/webapp/index.jsp file, it contains this part:

&lt;jsp:forward page=&quot;/login&quot;/&gt;

Actually, you have already accessed the index page successfully, and it redirects to the /login page which does not exist in your project so 404 here.

But you have an src/main/webapp/login.jsp file in this project, so you could access the http://localhost:8080/xxxx/login.jsp.

If you change the &lt;jsp:forward page=&quot;/login&quot;/&gt; to &lt;jsp:forward page=&quot;/login.jsp&quot;/&gt;, it would help too.

答案2

得分: 0

在部署选项卡中的应用上下文中添加"/"(斜杠)应该可以解决问题。

如果这不能解决问题,然后转到此页面。

英文:

Adding "/" (slash) to the Application context in the deployment tab should do it.

If that doesn't solve it, then go to this page.

huangapple
  • 本文由 发表于 2023年2月10日 11:02:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定