Skynet
posts - 138, comments - 150, trackbacks - 0, articles - 1
BlogJava
::
首页
::
新随笔
::
联系
::
聚合
::
管理
struct 2 apps 学习(1)
Posted on 2008-04-21 17:51
G_G
阅读(444)
评论(0)
编辑
收藏
所属分类:
struct
struts2-blank-2.0.11.1.war
web.xml:
<?
xml version="1.0" encoding="UTF-8"
?>
<
web-app
id
="WebApp_9"
version
="2.4"
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"
>
<
display-name
>
Struts Blank
</
display-name
>
<
filter
>
<
filter-name
>
struts2
</
filter-name
>
<!--
struct 2 处理类
-->
<!--
相应需要jar:
commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.11.1.jar
xwork-2.0.4.jar
-->
<
filter-class
>
org.apache.struts2.dispatcher.FilterDispatcher
</
filter-class
>
</
filter
>
<!--
默认覆盖
全部
路径
-->
<
filter-mapping
>
<
filter-name
>
struts2
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<!--
初始页面
-->
<
welcome-file-list
>
<
welcome-file
>
index.html
</
welcome-file
>
</
welcome-file-list
>
</
web-app
>
index.html:
<
head
>
<!--
利用html 跳转
-->
<
META
HTTP-EQUIV
="Refresh"
CONTENT
="0;URL=example/HelloWorld.action"
>
</
head
>
struct.xml
<!--
模块化注入
-->
<
include
file
="example.xml"
/>
<!--
Add packages here
-->
example.xml
<?
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
="example"
namespace
="/example"
extends
="struts-default"
>
<!--
域一般访问
-->
<
action
name
="HelloWorld"
class
="example.HelloWorld"
>
<
result
>
/example/HelloWorld.jsp
</
result
>
</
action
>
<!--
HelloWord.java(国际化) start -->
1
package
example;
2
3
/**
4
* import com.opensymphony.xwork2.ActionSupport;
5
6
public class ExampleSupport extends ActionSupport {
7
*/
8
public
class
HelloWorld
extends
ExampleSupport {
9
10
//
默认方法
11
public
String execute()
throws
Exception {
12
//
国际化方法使用 getText( key )
13
//
在url中体现->> HelloWorld.action?request_locale=en/es
14
//
国际化配置文件文件 package.properties和package_es.properties
15
setMessage(getText(MESSAGE));
16
return
SUCCESS;
17
}
18
19
/**
20
* Provide default valuie for Message property.
21
*/
22
public
static
final
String MESSAGE
=
"
HelloWorld.message
"
;
23
24
/**
25
* Field for Message property.
26
*/
27
private
String message;
28
29
/**
30
* Return Message property.
31
*
32
*
@return
Message property
33
*/
34
public
String getMessage() {
35
return
message;
36
}
37
38
/**
39
* Set Message property.
40
*
41
*
@param
message Text to display on HelloWorld page.
42
*/
43
public
void
setMessage(String message) {
44
this
.message
=
message;
45
}
46
}
<!--
HelloWord.java(国际化) end-->
<!--
(关键:action利用正则选择方法)Login(_*) >method="{1}"
-->
<
action
name
="Login_*"
method
="{1}"
class
="example.Login"
>
<
result
name
="input"
>
/example/Login.jsp
</
result
>
<
result
type
="redirect-action"
>
Menu
</
result
>
</
action
>
<!-
- example.Login(验证框架) start -->
java
1
public
class
Login
extends
ExampleSupport {
2
3
public
String execute()
throws
Exception {
4
5
if
(isInvalid(getUsername()))
return
INPUT;
6
7
if
(isInvalid(getPassword()))
return
INPUT;
8
9
return
SUCCESS;
10
}
11
12
private
boolean
isInvalid(String value) {
13
return
(value
==
null
||
value.length()
==
0
);
14
}
Login-validation.xml
1
<!
DOCTYPE validators PUBLIC
2
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
3
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"
>
4
5
<
validators
>
6
<
field
name
="username"
>
7
<
field-validator
type
="requiredstring"
>
8
<
message
key
="requiredstring"
/>
9
</
field-validator
>
10
</
field
>
11
<
field
name
="password"
>
12
<
field-validator
type
="requiredstring"
>
13
<
message
key
="requiredstring"
/>
14
</
field-validator
>
15
</
field
>
16
</
validators
>
17
<!-
- example.Login(验证框架) end -->
<!--
jsp 封包 如:Missing.action就是Missiong.jsp
-->
<
action
name
="*"
class
="example.ExampleSupport"
>
<
result
>
/example/{1}.jsp
</
result
>
</
action
>
<!--
Add actions here
-->
</
package
>
</
struts
>
新闻频道
新用户注册
刷新评论列表
标题
姓名
主页
验证码
*
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2008-04-21 18:19 编辑过
博客园
BlogJava
博客生活
IT博客网
C++博客
PHP博客
博客园社区
管理博客
教师博客
天文博客
汽车博客
足球博客
股票博客
电子博客
管理
相关文章:
struct 2 apps 学习(1)
Struts validation 小例
struts
Powered by:
BlogJava
Copyright © G_G
日历
<
2008年4月
>
日
一
二
三
四
五
六
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
公告
由于时间问题,
blog上一些表达都不太好。
在此我尽量把我参考的原文给大家,
帮助大家学习。^_^
有什么技术问题不会,
我很愿意和大家讨论!
多交流快成长
liukaiyi@gmail.com
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(6)
给我留言
查看公开留言
查看私人留言
随笔分类
ant(5)
AOP(5)
Database(8)
E_Study(1)
EJB(4)
hibernate(23)
HTML(3)
Inspiration(9)
Jakarta Commons(3)
javaGeneral(22)
javascript(19)
javascript Framework(7)
JDBC(5)
json(3)
JspTag(7)
JUnit(7)
Other(3)
Reportform(3)
Spring(4)
struct(4)
Swing(1)
xml Related(7)
随笔档案
2008年7月 (9)
2008年6月 (9)
2008年5月 (5)
2008年4月 (11)
2008年3月 (6)
2008年1月 (8)
2007年12月 (13)
2007年11月 (13)
2007年10月 (15)
2007年9月 (11)
2007年8月 (9)
2007年7月 (7)
2007年6月 (6)
2007年5月 (3)
2007年4月 (9)
文章档案
2007年4月 (1)
相册
EJB
hbn
ss
wz
hibernate
cjdbc
hibernate.cache
Hibernate中outer-join、lazy 、fetch join关键字的使用
My连接
一个读取Gmail邮件的简单程序
bat 1%
eXtremeTable limit
java+web
jsp java javascrip 交互
JS函数集合大全
strut c:
Struts Menu
tree jsp
上手JFreeChart
关键笔记
根据name调用getName方法
用JAVA实现一个分页类
搜索
最新评论
1. re: 实用,简单 ibatis dome (包含多对一;一对多)[未登录]
评论内容较长,点击标题查看
--JAVAFANS
2. re: 实用,简单 ibatis dome (包含多对一;一对多)
评论内容较长,点击标题查看
--JAVAFAN
3. re: 我的 ssh demo
文件下载路径以修改
--G_G
4. re: 我的 ssh demo
下不了啊,lsqlister@gmail.com
--lsqlister
5. re: 我的 ssh demo
下不了,请发到我的邮箱里好吗?谢谢TIANYXI@126.COM
--TYXING
阅读排行榜
1. select集连+xml+选择提交 (Ajax局部刷新) (1836)
2. CGLib 学习(1591)
3. WEB xml 画图 (javascript包装)用到 prototype.js wz_jsgraphics.js (1559)
4. google svn 服务器使用(1541)
5. json 使用(1522)
评论排行榜
1. hibernate 多服务器数据同步问题(支持延迟同步)(10)
2. 为在平安夜还在加班的程序员祝福!(8)
3. 权限设计的探讨阅读后感(6)
4. dom4j 学习(6)
5. Ajax uri 乱码问题总结(IE,FF)(6)
60天内阅读排行
1. google svn 服务器使用(1541)
2. Hibernate 数据库设计_1(1307)
3. mysql 树形结构数据收集(存储过程)(1211)
4. scilab 工具使用(1115)
5. java xml basex 数据库(1062)