gpt4 book ai didi

java - 如何解决 Tomcat 8/Library/Tomcat/work/Catalina/localhost 目录中缺少的 servlet 类?

转载 作者:行者123 更新时间:2023-11-28 22:55:37 25 4
gpt4 key购买 nike

我创建了一个简单的应用程序,在登录到 index.jsp 后,用户可以单击一个链接并使用链接到该链接的 servlet。问题是我没有看到在/Library/Tomcat/work/Catalina/localhost 中生成任何 servlet 类(存在 index.jsp 类)。

相关文件如下:

pom.xml

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.skiabox.webapps</groupId>
<artifactId>TheWebApp1</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>TheWebApp1 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>TomcatServer</server>
</configuration>
</plugin>
</plugins>
<finalName>TheWebApp1</finalName>
</build>
</project>

索引.jsp :

<html>
<head>
<title>My Home Page</title>
</head>
<body>
<h2>Hello World!</h2>

Hello from index.jsp!
Check your HelloWorld servlet <a href="HelloWorld">here</a>
</body>
</html>

网络.xml :

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
</web-app>

Hello World .java :

package gui;

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

/**
* Created by Administrator on 12/01/15.
*/
@WebServlet(name = "/HelloWorld/*")
public class HelloWorld extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<b>Hello World</b>");
out.println("</html>");
}
}

我正在使用 tomcat maven 插件来编译和部署项目(从 pom.xml 文件中可以很容易地看到)

最佳答案

你有没有把 webservlet 的名字和 urlPatterns 搞混了?尝试:

@WebServlet("/HelloWorld/*")

或者也许:

@WebServlet(name = "HelloWorld", urlPatterns = "/HelloWorld/*")

关于java - 如何解决 Tomcat 8/Library/Tomcat/work/Catalina/localhost 目录中缺少的 servlet 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27910577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com