Anonymous avatar Anonymous committed ed1dd6a

Added maven-webapp25 and made maven-webapp 3.0 template.

Comments (0)

Files changed (14)

maven-webapp/README.txt

 # Description
 
-A Java web application.
+A Java Servlet 3.0 web application.
 
 # Usage
 

maven-webapp/pom.xml

 		</dependency>
 		<dependency>
 			<groupId>javax.servlet</groupId>
-			<artifactId>servlet-api</artifactId>
-			<version>2.5</version>
+			<artifactId>javax.servlet-api</artifactId>
+			<version>3.1-b05</version>
 			<scope>provided</scope>
 		</dependency>
-		<dependency>
-			<groupId>javax.servlet</groupId>
-			<artifactId>jstl</artifactId>
-			<version>1.1.2</version>
-		</dependency>
-		<dependency>
-			<groupId>taglibs</groupId>
-			<artifactId>standard</artifactId>
-			<version>1.1.2</version>
-		</dependency>
-		<!-- JSP
-		<dependency>
-			<groupId>javax.servlet.jsp</groupId>
-			<artifactId>jsp-api</artifactId>
-			<version>2.1</version>
-			<scope>provided</scope>
-		</dependency> -->
 
 	</dependencies>
 </project>

maven-webapp/src/main/java/deng/HealthServlet.java

+package deng;
+
+import java.io.IOException;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The main servlet that fetch web application views.
+ * @author Zemian Deng <saltnlight5@gmail.com>
+ */
+@WebServlet(value="/health")
+public class HealthServlet extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+	private static Logger logger = LoggerFactory.getLogger(HealthServlet.class);
+
+	@Override
+	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		logger.trace("Request URI: {}", req.getRequestURI());
+		req.getRequestDispatcher("health.jsp").forward(req, resp);
+	}
+}

maven-webapp/src/main/java/deng/HomeServlet.java

+package deng;
+
+import java.io.IOException;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The main servlet that fetch web application views.
+ * @author Zemian Deng <saltnlight5@gmail.com>
+ */
+@WebServlet(value="/home", loadOnStartup=1)
+public class HomeServlet extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+	private static Logger logger = LoggerFactory.getLogger(HomeServlet.class);
+
+	@Override
+	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		logger.trace("Request URI: {}", req.getRequestURI());
+		req.setAttribute("appPath", getServletContext().getRealPath(""));
+		req.setAttribute("appVersion", getServletContext().getMajorVersion() + "/" +
+			getServletContext().getMinorVersion());
+		req.getRequestDispatcher("home.jsp").forward(req, resp);
+	}
+}

maven-webapp/src/main/java/deng/MainServlet.java

-package deng;
-
-import java.io.IOException;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The main servlet that fetch web application views.
- * @author Zemian Deng <saltnlight5@gmail.com>
- */
-public class MainServlet extends HttpServlet {
-	private static final long serialVersionUID = 1L;
-	private static Logger logger = LoggerFactory.getLogger(MainServlet.class);
-
-	@Override
-	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
-		logger.trace("Request URI: {}", req.getRequestURI());
-		String reqURI = req.getRequestURI();
-		int baseLen = req.getContextPath().length() + req.getServletPath().length();
-		final String reqPath;
-		if (reqURI.length() > baseLen)
-			reqPath = reqURI.substring(baseLen);
-		else
-			reqPath = "/home";
-		logger.debug("Request path: " + reqPath);
-		process(reqPath, req);
-		req.getRequestDispatcher(reqPath + ".jsp").forward(req, resp);
-	}
-
-	protected void process(String reqPath, HttpServletRequest req) throws ServletException {
-		if (reqPath.equals("/home")) {
-			req.setAttribute("appPath", getServletContext().getRealPath(""));
-			req.setAttribute("appVersion", getServletContext().getMajorVersion() + "/" +
-				getServletContext().getMinorVersion());
-		}
-	}
-}

maven-webapp/src/main/webapp/WEB-INF/web.xml

 <?xml version="1.0"?>
-<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+<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">
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+	version="3.0">
 
 	<description>Java Web Application</description>
 	<welcome-file-list>
-		<welcome-file>main</welcome-file>
+		<welcome-file>home</welcome-file>
 	</welcome-file-list>
-	<servlet>
-		<servlet-name>MainServlet</servlet-name>
-		<servlet-class>deng.MainServlet</servlet-class>
-	</servlet>
-	<servlet-mapping>
-		<servlet-name>MainServlet</servlet-name>
-		<url-pattern>/main/*</url-pattern>
-	</servlet-mapping>
 
 </web-app>

maven-webapp/src/main/webapp/home.jsp

 
 		<h2>Utilities</h2>
 		<ul>
-		<li><a href="${pageContext.request.contextPath}/main/health">Health Check</a></li>
+		<li><a href="${pageContext.request.contextPath}/health">Health Check</a></li>
 		</ul>
 	</body>
 </html>

maven-webapp25/README.txt

+# Description
+
+A Java Servlet 2.5 web application.
+
+# Usage
+
+$ mvn install
+$ mvn tomcat7:run
+$ open http://localhost:8080/maven-webapp

maven-webapp25/pom.xml

+<?xml version="1.0"	encoding="UTF-8"?>
+<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>deng</groupId>
+	<artifactId>maven-webapp</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<packaging>war</packaging>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<slf4j.version>1.7.1</slf4j.version>
+	</properties>
+
+	<build>
+		<finalName>${project.artifactId}</finalName>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.tomcat.maven</groupId>
+				<artifactId>tomcat7-maven-plugin</artifactId>
+				<version>2.0</version>
+			</plugin>
+			<plugin>
+				<artifactId>maven-deploy-plugin</artifactId>
+				<version>2.7</version>
+				<configuration>
+					<skip>true</skip>
+				</configuration>
+			</plugin>
+			<plugin>
+				<artifactId>maven-install-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<skip>true</skip>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.hamcrest</groupId>
+			<artifactId>hamcrest-library</artifactId>
+			<version>1.3</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit-dep</artifactId>
+			<version>4.11</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>${slf4j.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+			<version>${slf4j.version}</version>
+			<scope>runtime</scope>
+			<optional>true</optional>
+		</dependency>
+		<dependency>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.6</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-io</groupId>
+			<artifactId>commons-io</artifactId>
+			<version>2.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>servlet-api</artifactId>
+			<version>2.5</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>jstl</artifactId>
+			<version>1.1.2</version>
+		</dependency>
+		<dependency>
+			<groupId>taglibs</groupId>
+			<artifactId>standard</artifactId>
+			<version>1.1.2</version>
+		</dependency>
+		<!-- JSP
+		<dependency>
+			<groupId>javax.servlet.jsp</groupId>
+			<artifactId>jsp-api</artifactId>
+			<version>2.1</version>
+			<scope>provided</scope>
+		</dependency> -->
+
+	</dependencies>
+</project>

maven-webapp25/src/main/java/deng/MainServlet.java

+package deng;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The main servlet that fetch web application views.
+ * @author Zemian Deng <saltnlight5@gmail.com>
+ */
+public class MainServlet extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+	private static Logger logger = LoggerFactory.getLogger(MainServlet.class);
+
+	@Override
+	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		logger.trace("Request URI: {}", req.getRequestURI());
+		String reqURI = req.getRequestURI();
+		int baseLen = req.getContextPath().length() + req.getServletPath().length();
+		final String reqPath;
+		if (reqURI.length() > baseLen)
+			reqPath = reqURI.substring(baseLen);
+		else
+			reqPath = "/home";
+		logger.debug("Request path: " + reqPath);
+		process(reqPath, req);
+		req.getRequestDispatcher(reqPath + ".jsp").forward(req, resp);
+	}
+
+	protected void process(String reqPath, HttpServletRequest req) throws ServletException {
+		if (reqPath.equals("/home")) {
+			req.setAttribute("appPath", getServletContext().getRealPath(""));
+			req.setAttribute("appVersion", getServletContext().getMajorVersion() + "/" +
+				getServletContext().getMinorVersion());
+		}
+	}
+}

maven-webapp25/src/main/resources/log4j.properties

+#
+# A log4j configuration file
+#
+
+# Basic STDOUT logger appender.
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.conversionPattern=%d{HH:mm:ss} %t %-5p %c:%L | %m%n
+
+# A rolling file logger appender.
+#log4j.appender.FILE=org.apache.log4j.RollingFileAppender
+#log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
+#log4j.appender.FILE.layout.conversionPattern=%d %-5p %t %c| %m%n
+#log4j.appender.FILE.threshold=DEBUG
+#log4j.appender.FILE.append=true
+#log4j.appender.FILE.file=application.log
+
+# Root logger level
+log4j.rootLogger = INFO, CONSOLE
+
+# Application logger level
+log4j.logger.deng = DEBUG

maven-webapp25/src/main/webapp/WEB-INF/web.xml

+<?xml version="1.0"?>
+<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">
+
+	<description>Java Web Application</description>
+	<welcome-file-list>
+		<welcome-file>main</welcome-file>
+	</welcome-file-list>
+	<servlet>
+		<servlet-name>MainServlet</servlet-name>
+		<servlet-class>deng.MainServlet</servlet-class>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>MainServlet</servlet-name>
+		<url-pattern>/main/*</url-pattern>
+	</servlet-mapping>
+
+</web-app>

maven-webapp25/src/main/webapp/health.jsp

+1

maven-webapp25/src/main/webapp/home.jsp

+<html>
+	<head><title>Java Web Application</title></head>
+	<body>
+		<h1>Welcome</h1>
+
+		<p>Your application is ready.</p>
+		<pre>Application RealPath: ${appPath}</pre>
+		<pre>Servlet Version: ${appVersion}</pre>
+		<pre>ContextPath: ${pageContext.request.contextPath}</pre>
+
+		<h2>Utilities</h2>
+		<ul>
+		<li><a href="${pageContext.request.contextPath}/main/health">Health Check</a></li>
+		</ul>
+	</body>
+</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.