GAE中使用struts2技术

本文适用人群:有一定的编程基础、申请成功gae项目、本机环境搭建完成、会给GAE绑定域名(是Google apps用户)

没有废话,直接开始:

1、新建一个Google app engine(下简称GAE)项目

填写项目名称和包名(随意写)

填写名字和包填写名字和包

2、观察系统组成

structureOfGae

3、导入Struts2支持包

注意,除了这些:

导入包1

我们常用的包,我们还需要导入以下两个包:

import2

说明:commons-logging-1.0.4.jar 在struts2.1.8的包里自带

struts2-gae-0.1.jar 下载自:

http://code.google.com/p/struts2-gae/downloads/list

疑问,包导入会自动上传吗?包导到哪里去了?build path是什么?

首先将包导入lib目录

libs

然后选择Configure Build Path

configBuildPath

把刚刚导入的Jar包添加到build path里

addToBP

那么到现在,我们的struts2和gae环境支持已经搭建完毕

4、配置web.xml(重要)

4.1 观察

webxml

4.2 编写代码
为web.xml加入一个filter映射和一个监听器

1
2
3
4
5
6
7
8
9
10
11
12
<filter>
	<filter-name>struts2-gae</filter-name>
	<filter-class>com.struts2.gae.dispatcher.GaeFilterDispatcher</filter-class>
</filter>
<filter-mapping>
	<filter-name>struts2-gae</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>
 
<listener>
<listener-class>com.struts2.gae.listener.OgnlListener</listener-class>
</listener>

5、代码编写

5.1 新建一个action
newAction

代码testAction.java

1
2
3
4
5
6
7
package org.mobai.gae.action;
import com.opensymphony.xwork2.ActionSupport;
    public class testAction extends ActionSupport {
        public String execute(){
            return SUCCESS;
        }
}

5.2 建立一个成功页面:代码success.jsp

1
2
3
4
5
6
7
8
9
10
11
12
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>SUCCESS!!</h1>
</body>
</html>

5.3 配置struts.xml

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
 
<struts>
<package name="gaeStruts2" namespace="/" extends="struts-default">
		<action name="test" class="org.mobai.gae.action.testAction">
			<result>success.jsp</result>
		</action>
	</package>
</struts>

代码说明:很简单的一个请求跳转功能的实现

6、部署

部署设置
image

部署设置

点击部署
image

点击部署

填写帐户名和密码
image

填写Gmail用户名和密码

部署成功图
image

部署成功!

预览:http://gae.dev.mobai.org/ 根据本人以后的探索,此页面将会不停的变动,请谅解!

为了节省流量,图片经过压缩处理,可在这里留言获得jar包和pdf清晰版。

38 thoughts on “GAE中使用struts2技术

    • @TT, oh yeah.Google app engine 是一个很不错的东西,已经把lib包和ppt发给你了,我们多交流交流啊,最近要去上专升本补习班了,不能研究了,痛哭啊。。

  1. Google App Engine 爱好者交流QQ群:9152640
    大家来群里交流交流啊

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">