Quellcode durchsuchen

Basic configuration ready.

Tom Flucke vor 7 Jahren
Ursprung
Commit
59d5588b1d

+ 2 - 2
build.xml

@@ -69,12 +69,12 @@
   
   <target name="war" depends="compile" description="Create application WAR">
 	<mkdir dir="${build.dir}"/>
-	<war warfile="${build.warfile}" 
-		 webxml="web.xml">
+	<war warfile="${build.warfile}" webxml="web.xml">
       <lib dir="${compile.dependencies}">
         <exclude name="*sources.jar"/>
         <exclude name="*javadoc.jar"/>
       </lib>
+      <fileset dir="web"/>
       <classes dir="${target.dir}"/>
     </war>
   </target>

+ 11 - 2
src/name/tflucke/ieat2/AppInitializer.java

@@ -4,6 +4,8 @@ import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatche
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import name.tflucke.ieat2.controllers.*;
+
 public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
 
     //private static final Log LOGGER = LogFactory.getLog(WebInitializer.class);
@@ -14,16 +16,23 @@ public class AppInitializer extends AbstractAnnotationConfigDispatcherServletIni
          *  your root config class should @Import other configs 
          *  to make them work without needing them to add there
          */
-        return new Class[] {};
+        return new Class[] {WebConfig.class};
     }
 
     @Override
     protected Class<?>[] getServletConfigClasses() {
-        return new Class[] {TestController.class};
+        return new Class[] {TestController.class, ViewController.class};
     }
 
     @Override
     protected String[] getServletMappings() {
         return new String[] { "/" };
     }
+
+    /*
+    @Override
+    protected Filter[] getServletFilters() {
+        return new Filter[] {};
+    }
+    */
 }

+ 25 - 0
src/name/tflucke/ieat2/WebConfig.java

@@ -0,0 +1,25 @@
+package name.tflucke.ieat2;
+ 
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.view.InternalResourceViewResolver;
+import org.springframework.web.servlet.view.JstlView;
+ 
+@Configuration
+@EnableWebMvc
+@ComponentScan(basePackages = "name.tflucke.ieat2")
+public class WebConfig {
+    @Bean
+    public ViewResolver viewResolver() {
+        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
+        viewResolver.setViewClass(JstlView.class);
+        viewResolver.setPrefix("/views/");
+        viewResolver.setSuffix(".jsp");
+ 
+        return viewResolver;
+    }
+ 
+}

+ 2 - 2
src/name/tflucke/ieat2/TestController.java → src/name/tflucke/ieat2/controllers/TestController.java

@@ -1,10 +1,10 @@
-package name.tflucke.ieat2;
+package name.tflucke.ieat2.controllers;
 
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 
-@RestController
+@RestController("/echo/")
 public class TestController {
     @GetMapping("/echo/{name}")
     public String echo(@PathVariable("name") String name) {

+ 23 - 0
src/name/tflucke/ieat2/controllers/ViewController.java

@@ -0,0 +1,23 @@
+package name.tflucke.ieat2.controllers;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.PathVariable;
+ 
+@Controller
+@RequestMapping("/")
+public class ViewController {
+ 
+    @RequestMapping
+    public String defaultPage(ModelMap model) {
+        return "index";
+    }
+ 
+    @RequestMapping(value = "/{file}")
+    public String arbitraryFile(@PathVariable("file") String filename, ModelMap model) {
+        return filename;
+    }
+ 
+}

+ 1 - 196
web.xml

@@ -1,203 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-	Copyright (c) 2002-2006 Matt Magoffin
-	
-	This program is free software; you can redistribute it and/or 
-	modify it under the terms of the GNU General Public License as 
-	published by the Free Software Foundation; either version 2 of 
-	the License, or (at your option) any later version.
-	
-	This program is distributed in the hope that it will be useful, 
-	but WITHOUT ANY WARRANTY; without even the implied warranty of 
-	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
-	General Public License for more details.
-	
-	You should have received a copy of the GNU General Public License 
-	along with this program; if not, write to the Free Software 
-	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
-	02111-1307 USA
-	
-	$Id: web.xml,v 1.4 2006/11/28 09:23:25 matt Exp $
--->
 <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 	     version="5.0">
-  <display-name>Online recipe manager.</display-name>
-  
-  <resource-ref>
-	<res-ref-name>jdbc/ieat</res-ref-name>
-	<res-type>javax.sql.DataSource</res-type>
-	<res-auth>Container</res-auth>
-	<res-sharing-scope>Shareable</res-sharing-scope>
-  </resource-ref>
-
-  <context-param>
-	<param-name>webAppRootKey</param-name>
-	<param-value>ieat.root.dir</param-value>
-  </context-param>
-  
-  <!--
-	  <context-param>
-	  <param-name>log4jConfigLocation</param-name>
-	  <param-value>log4j.properties</param-value>
-	  </context-param>
-  -->
-  
-  <!-- 
-	   Static content client-side cache headers filter
-  -->
-  <!--
-  <filter>
-	<filter-name>Client-side Cache Headers Filter</filter-name>
-	<filter-class>magoffin.matt.xweb.util.ResponseHeaderFilter</filter-class>
-	<init-param>
-	  <param-name>Cache-Control</param-name>
-	  <param-value>max-age=86400</param-value>
-	</init-param>
-  </filter>
-  -->
-  
-  <!-- Compression filter -->
-  <!--
-  <filter>
-	<filter-name>Compression Filter</filter-name>
-	<filter-class>compressionFilters.CompressionFilter</filter-class>
-	<init-param>
-	  <param-name>compressionThreshold</param-name>
-	  <param-value>10</param-value>
-	</init-param>
-	<init-param>
-	  <param-name>debug</param-name>
-	  <param-value>0</param-value>
-	</init-param>
-  </filter>
--->
-  
-  <!-- Use UTF-8 character encoding -->
-  <!--
-  <filter>
-	<filter-name>Set Character Encoding</filter-name>
-	<filter-class>filters.SetCharacterEncodingFilter</filter-class>
-	<init-param>
-	  <param-name>encoding</param-name>
-	  <param-value>UTF-8</param-value>
-	</init-param>
-  </filter>
-  -->
-  
-  <!-- Cache filter -->
-  <!--
-  <filter-mapping>
-	<filter-name>Client-side Cache Headers Filter</filter-name>
-	<url-pattern>*.js</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Client-side Cache Headers Filter</filter-name>
-	<url-pattern>*.css</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Client-side Cache Headers Filter</filter-name>
-	<url-pattern>*.gif</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Client-side Cache Headers Filter</filter-name>
-	<url-pattern>*.jpg</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Client-side Cache Headers Filter</filter-name>
-	<url-pattern>*.png</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Client-side Cache Headers Filter</filter-name>
-	<url-pattern>*.html</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Client-side Cache Headers Filter</filter-name>
-	<url-pattern>/messages.json</url-pattern>
-  </filter-mapping>
-  -->
-  
-  <!-- Compression filter -->
-  <!--
-  <filter-mapping>
-	<filter-name>Compression Filter</filter-name>
-	<url-pattern>*.css</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Compression Filter</filter-name>
-	<url-pattern>*.do</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Compression Filter</filter-name>
-	<url-pattern>*.html</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Compression Filter</filter-name>
-	<url-pattern>*.js</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Compression Filter</filter-name>
-	<url-pattern>*.json</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-	<filter-name>Compression Filter</filter-name>
-	<url-pattern>*.txt</url-pattern>
-  </filter-mapping>
-  -->
-  
-  <!--
-  <filter-mapping>
-	<filter-name>Set Character Encoding</filter-name>
-	<servlet-name>ieat</servlet-name>
-  </filter-mapping>
-  -->
-  
-  <!--
-	  <listener>
-	  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
-	  </listener>
-  -->
-
-  <!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext
-       instead of the default XmlWebApplicationContext -->
-  <context-param>
-    <param-name>contextClass</param-name>
-    <param-value>
-      org.springframework.web.context.support.AnnotationConfigWebApplicationContext
-    </param-value>
-  </context-param>
-
-  <!-- Configuration locations must consist of one or more comma- or space-delimited
-       fully-qualified @Configuration classes. Fully-qualified packages may also
-       be specified for component-scanning -->
-  <context-param>
-    <param-name>contextConfigLocation</param-name>
-    <param-value>com.nirav.modi.config.SpringAppConfig</param-value>
-  </context-param>
 
-  <listener>
-	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
-  </listener>
-
-  <!--
-  <servlet>
-	<servlet-name>ieat</servlet-name>
-	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
-	<load-on-startup>1</load-on-startup>
-  </servlet>
-
-  <servlet-mapping>
-	<servlet-name>ieat</servlet-name>
-	<url-pattern>*.do</url-pattern>
-  </servlet-mapping>
-  <servlet-mapping>
-	<servlet-name>ieat</servlet-name>
-	<url-pattern>*.json</url-pattern>
-  </servlet-mapping>
-  -->
-
-  <welcome-file-list>
-	<welcome-file>index.jsp</welcome-file>
-  </welcome-file-list>
+  <display-name>Online recipe manager.</display-name>
 </web-app>

+ 14 - 0
web/views/index.jsp

@@ -0,0 +1,14 @@
+<%@ page language="java" contentType="text/html; charset=US-ASCII"
+    pageEncoding="US-ASCII"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>iEat - Home</title>
+  </head>
+  <body>
+    <h1>iEat 2.0</h1>
+    <%@ page import="java.util.Date" %>
+    <span>Current Time is</span>: <%= new Date() %>
+  </body>
+</html>