Appengine部署springMVC3.1

参考: http://sikeh.iteye.com/blog/364043
获得springMVC的方法: http://panyongzheng.iteye.com/blog/1759912

1. mvn archetype:create -DgroupId=com.pandy -DartifactId=study
2. cd study
需要做一些另外的事情,然后再打包,得到的pom.xml如下:
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.pandy</groupId>
  <artifactId>study</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>study</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
	<dependency>  
            <!-- 增加spring-webmvc依赖 -->  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-webmvc</artifactId>  
            <version>3.1.2.RELEASE</version>  
        </dependency> 
  </dependencies>
  
  <build>  
        <plugins>  
            	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-dependency-plugin</artifactId>
		<executions>
			<execution>
				<id>copy</id>
				<phase>install</phase>
				<goals>
					<goal>copy-dependencies</goal>
				</goals>
				<configuration>
					<outputDirectory>$/lib</outputDirectory>
					-->拷贝所以依赖存放位置
				</configuration>
			</execution>
		</executions>
	</plugin>  
  
        </plugins>  
    </build> 
</project>


3.mvn dependency:copy-dependencies
所有依赖的jar文件将被复制到target/dependency目录下。得到所有springmvc的依赖包.
并加入:jstl.jar ,standard.jar

4.在eclipse建立appengine项目.

5.web.xml加入:
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<servlet>
		<servlet-name>dispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dispatcher</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>


6.war/WEB-INF/dispatcher-servlet.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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

	<context:component-scan base-package="com.gae.pandy.controller" />
	<mvc:annotation-driven />

	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/views/" p:suffix=".jsp" />

</beans>


7.war/views/test.jsp
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
	Hi,
	<c:out value="${name}" />
	<br /> It works!
	<br />
	<a href="/index.jsp">Back</a>
</body>
</html>


8.index.jsp
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
	<form action="test.do" method="post">
		your name: <br /> <input type="text" name="name" /> <br /> <input
			type="submit" value="Submit" />
	</form>

</body>
</html>


9.Controller
package com.gae.pandy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class TestController {

	@RequestMapping(value = "/test.do", method = RequestMethod.POST)
	public String test(String name, Model model) {
		model.addAttribute("name", name);
		return "test";
	}
}


10.http://localhost:8888/index.jsp  测试springmvc






附:
aopalliance-1.0.jar
appengine-api-1.0-sdk-1.7.4.jar
appengine-api-labs.jar
appengine-endpoints.jar
appengine-jsr107cache-1.7.4.jar
apps-marketplace.jar
asm-4.0.jar
commons-logging-1.1.1.jar
datanucleus-api-jdo-3.1.1.jar
datanucleus-api-jpa-3.1.1.jar
datanucleus-appengine-2.1.1.jar
datanucleus-core-3.1.1.jar
geronimo-jpa_2.0_spec-1.0.jar
jdo-api-3.0.1.jar
jsr107cache-1.1.jar
jstl.jar
jta-1.1.jar
junit-3.8.1.jar
spring-aop-3.1.2.RELEASE.jar
spring-asm-3.1.2.RELEASE.jar
spring-beans-3.1.2.RELEASE.jar
spring-context-3.1.2.RELEASE.jar
spring-context-support-3.1.2.RELEASE.jar
spring-core-3.1.2.RELEASE.jar
spring-expression-3.1.2.RELEASE.jar
spring-web-3.1.2.RELEASE.jar
spring-webmvc-3.1.2.RELEASE.jar
standard.jar

你可能感兴趣的:(springMVC)