Reputation: 13
I have the following servlet coded in /src/main/java/examples/web/SimpleServlet.java
:
package examples.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SimpleServlet extends HttpServlet {
public void goGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
PrintWriter writer = res.getWriter();
writer.println("SimpleServlet Executed!");
writer.flush();
writer.close();
}
}
And the following web.xml defined in src/main/webapp/WEB-INF/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>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>examples.web.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/simpleservlet</url-pattern>
</servlet-mapping>
</web-app>
And the following pom.xml defined in /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>examples.web</groupId>
<artifactId>simple-webapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>simple-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>simple-webapp</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
When I run mvn jetty:run
I get output indicating that everything is working correctly. When I load localhost:8080/simple-webapp
I am served src/main/webapp/index.jsp
, so I know Jetty is at least partially working.
And now for the question: Although I am able to get to index.jsp
, I cannot get to /simple-webapp/SimpleServlet
-- I just get a 404 error from Jetty. Because of my configuration in web.xml
, I was expecting to see SimpleServlet Executed!
from SimpleServlet
. What am I doing wrong?
Here is the relevant output from mvn jetty:run
:
[INFO] Configuring Jetty for project: simple-webapp Maven Webapp
[INFO] Webapp source directory = C:\Users\Ken\Workspace\Eclipse\Maven\simple-webapp\src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:\Users\Ken\Workspace\Eclipse\Maven\simple-webapp\target\classes
2011-11-23 16:59:56.220:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Context path = /simple-webapp
[INFO] Tmp directory = determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = C:\Users\Ken\Workspace\Eclipse\Maven\simple-webapp\src\main\webapp\WEB-INF\web.xml
[INFO] Webapp directory = C:\Users\Ken\Workspace\Eclipse\Maven\simple-webapp\src\main\webapp
Upvotes: 1
Views: 2220
Reputation: 3456
The URLs are case-sensitive. The defined URL pattern does not match the value that you are requesting:
<url-pattern>/simpleservlet</url-pattern>
Try http://localhost:8080/simple-webapp/simpleservlet (lowercase servlet name).
Upvotes: 1