Commits

James Sumners committed 32c55a6

Added and example controller with a view.

Comments (0)

Files changed (5)

 
     <war-plugin.version>2.3</war-plugin.version>
     <log4j.version>1.2.16</log4j.version>
+    <slf4j.version>1.7.4</slf4j.version>
     <spring.version>3.1.4.RELEASE</spring.version>
   </properties>
 
     </dependency>
 
     <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>jstl</groupId>
+      <artifactId>jstl</artifactId>
+      <version>1.2</version>
+    </dependency>
+
+    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-webmvc</artifactId>
       <version>${spring.version}</version>

src/main/java/com/example/MyWebApplication/ExampleApp.java

+package com.example.MyWebApplication;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.context.request.WebRequest;
+
+@Controller
+public class ExampleApp {
+  private static final Logger logger = LoggerFactory.getLogger(ExampleApp.class);
+
+  @RequestMapping("/helloWorld")
+  public String helloWorld(WebRequest request) {
+    logger.info("/helloWorld -> " + request.toString());
+
+    // Do nothing except return the "view" name to load.
+    return "helloWorld";
+  }
+}

src/main/resources/log4j.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration PUBLIC "-//LOGGER" "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+  <!-- Appenders -->
+  <appender name="console" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out" />
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%-5p: %c - %m%n" />
+    </layout>
+  </appender>
+
+  <!-- 3rdparty Loggers -->
+  <logger name="org.springframework.core">
+    <level value="info" />
+  </logger>
+
+  <logger name="org.springframework.beans">
+    <level value="info" />
+  </logger>
+
+  <logger name="org.springframework.context">
+    <level value="info" />
+  </logger>
+
+  <logger name="org.springframework.web">
+    <level value="info" />
+  </logger>
+
+  <!-- Root Logger -->
+  <root>
+    <priority value="warn" />
+    <appender-ref ref="console" />
+  </root>
+
+</log4j:configuration>

src/main/webapp/WEB-INF/jsp/helloWorld.jsp

+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>An Example View</title>
+</head>
+<body>
+  <h1>Hello world!</h1>
+
+  <c:forEach var="i" begin="0" end="5" step="1">
+    <p><c:out value="${i}" /></p>
+  </c:forEach>
+</body>
+</html>

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

 
   <servlet-mapping>
     <servlet-name>springmvc-skel</servlet-name>
-    <url-pattern>/*</url-pattern>
+    <url-pattern>/</url-pattern>
+    <!--
+      You'd think you can map "/*" here but that causes much pain:
+      http://blog.anorakgirl.co.uk/2008/11/spring-web-mvc-and-url-mapping/
+      http://stackoverflow.com/questions/2129876
+    -->
   </servlet-mapping>
 
   <welcome-file-list>