0
我創建了一個簡單的應用程序,登陸到index.jsp後,用戶可以單擊鏈接並使用鏈接到此鏈接的servlet。 問題是我沒有看到/ Library/Tomcat/work/Catalina/localhost(index.jsp類存在)中生成的servlet類。如何解決從Tomcat 8/Library/Tomcat/work/Catalina/localhost目錄中缺少的servlet類?
以下是相關文件:
的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>
的index.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>
的web.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>
HelloWorld.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文件看到)
非常感謝您!我試圖使用urlPatterns,但沒有這種模式。 – skiabox