Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Sample jetty app

  • Loading branch information...
commit 4cceb7a8610e3f5a4f50173ec1de44a4424d09c1 1 parent 351013d
@lstoll authored
View
45 pom.xml
@@ -0,0 +1,45 @@
+<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>org.example</groupId>
+ <artifactId>hello-world</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Jetty HelloWorld</name>
+
+ <properties>
+ <jettyVersion>7.4.2.v20110526</jettyVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>${jettyVersion}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <!-- This plugin is needed for the servlet example -->
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <version>${jettyVersion}</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution><goals><goal>java</goal></goals></execution>
+ </executions>
+ <configuration>
+ <mainClass>org.example.HelloWorld</mainClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
View
18 src/main/java/org/example/HelloServlet.java
@@ -0,0 +1,18 @@
+package org.example;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class HelloServlet extends HttpServlet
+{
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println("<h1>Hello Servlet</h1>");
+ response.getWriter().println("session=" + request.getSession(true).getId());
+ }
+}
View
15 src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<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_2_5.xsd"
+ version="2.5">
+ <servlet>
+ <servlet-name>Hello</servlet-name>
+ <servlet-class>org.example.HelloServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Hello</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+</web-app>
View
2  src/main/webapp/index.html
@@ -0,0 +1,2 @@
+<h1>Hello World Java Webapp</h1>
+<a href="/hello">Hello Servlet</a>
Please sign in to comment.
Something went wrong with that request. Please try again.