- 建立專案
- 使用 Eclipse -> New Web Application Project
- 輸入 Project name 與 Package
- 取消勾選 Use Google Web Toolkit
- 確認勾選 Google App Engine
- 加入 Maven
- 修改 web.xml
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<!-- Reads request input using UTF-8 encoding -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- config Spring app ctx -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/vocabulary-appctx.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- config Spring web ctx -->
<servlet>
<servlet-name>vocabulary</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/vocabulary-webctx.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Initail</servlet-name>
<servlet-class>idv.neil.vocabulary.web.Initial</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>vocabulary</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
- 建立 Initial.java
package idv.neil.vocabulary.web;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
@SuppressWarnings("serial")
public class Initial extends HttpServlet {
private static final String G_LOGOUT_URL = "G_LOGOUT_URL";
@Override
public void init() throws ServletException {
UserService gus = UserServiceFactory.getUserService();
this.getServletContext().setAttribute(G_LOGOUT_URL, gus.createLogoutURL("/"));
}
}
- 建立 /war/WEB-INF/vocabulary-appctx.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="idv.neil.vocabulary.service,idv.neil.vocabulary.dao,idv.neil.vocabulary.model"/>
</beans>
- 建立 /war/WEB-INF/vocabulary-webctx.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="idv.neil.vocabulary.web.ctrl"/>
<mvc:annotation-driven/>
<mvc:interceptors>
<bean class="idv.neil.vocabulary.web.AuthenticationInterceptor"/>
</mvc:interceptors>
<bean class="org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver"/>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<value>/WEB-INF/tiles.xml</value>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>
</beans>
- 建立 /war/index.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:redirect url="/index.do" />
- 建立 IndexController.java
package idv.neil.vocabulary.web.ctrl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class IndexController {
private static final Logger log = LoggerFactory.getLogger(IndexController.class);
@RequestMapping("/index")
public ModelAndView index() {
ModelAndView mav = new ModelAndView("index");
return mav;
}
}
- 建立 /war/WEB-INF/tiles.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="index" template="/WEB-INF/jsp/layout/layout.jsp">
<put-attribute name="header" value="/WEB-INF/jsp/layout/header.jsp"/>
<put-attribute name="menu" value="/WEB-INF/jsp/layout/menu.jsp"/>
<put-attribute name="content" value="/WEB-INF/jsp/layout/content.jsp"/>
<put-attribute name="footer" value="/WEB-INF/jsp/layout/footer.jsp"/>
</definition>
</tiles-definitions>
- 建立 style/layout.css
沒有留言:
張貼留言