【问题标题】:Tomcat Deployment with IntelliJ - Server is not connected使用 IntelliJ 部署 Tomcat - 服务器未连接
【发布时间】:2017-01-21 02:13:23
【问题描述】:

我想用 maven 部署一个小型 Web 应用程序。我下载并配置了 tomcat 并告诉 IntelliJ 在 Run/Debug config 中使用它,如下所示。 我还配置它来构建神器“战争爆炸”。

问题是,每次我运行项目时,我都会收到一条错误消息:

工件 JDBCTest:war:服务器未连接。部署不是 可用。

Here's my dropbox with error log, pom.xml, servlet class etc.

我真的可以使用一些建议。

【问题讨论】:

标签: java maven tomcat intellij-idea


【解决方案1】:

因为你的源代码结构不正确。

(1) 创建文件夹结构:

.
├── pom.xml
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── servlet/
│   │   │       └── ServletHome.java
│   │   └── resources/
│   └── test/
│       ├── java/
│       └── resources/
└── webapp/
    ├── WEB-INF/
    │   └── web.xml
    └── hello.jsp

ServletHome.java

package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "servlethome", urlPatterns = {"/servlethome"})
public class ServletHome extends javax.servlet.http.HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().print("Hello World");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}

您的 webapp 可以通过 http://localhost:8080/servlethome 访问 如果您想直接在主页更改为urlPatterns = {"/"}

(2) 将这些行添加到 pom.xml 中

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

结果:

【讨论】:

  • 感谢它现在工作,但你知道如何在 tomcat 中显示 hello.jsp 内容吗?
  • 如果您想在localhost:8080 看到hello.jsp 的内容,请将内部文件ServletHome.javaurlPatterns = {"/servlethome"} 更改为urlPatterns = {"/"}
  • 我做到了,但它仍然在 localhost:18509 向我显示 hello world
  • 好的。让我们看看你的截图:i.stack.imgur.com/ADwim.png 再次,将 HTTP 端口:18509 更改为默认值 8080
猜你喜欢
  • 2015-02-23
  • 2014-09-28
  • 2015-07-20
  • 1970-01-01
  • 2015-08-23
  • 2019-07-09
  • 2013-12-08
  • 1970-01-01
  • 2014-08-14
相关资源
最近更新 更多