Struts2搭建过程
来源:互联网 发布:java switch 枚举 编辑:程序博客网 时间:2024/05/18 03:24
一、找到开发Struts2应用需要使用到的jar文件:
- asm-x.x.jar:官方说要加,但我不加也行
- asm-commons-x.x.jar:官方说要加,但我不加也行
- asm-tree-x.x.jar:官方说要加,但我不加也行
- Struts2-core-2.x.x.jar:Struts2框架的核心类库;
- xwork-2.x.x.jar :xwork类库,Struts2是在其之上构建的;
- ognl-2.6.x.jar:对象图导航语言(Object Graph Navigation Language),Struts2框架通过其读写对象属性;
- freemarker-2.2.x.jar:Struts2的UI标签的模板使用freemarker编写;
- commons-fileupload-1.2.1.jar:文件上传组件, 2.1.6版本后必须加入文件;
- javassist-3.11.0.GA.jar:Javassist是一个开源的分析、编辑和创建Java字节码的类库;
- commons-io-2.0.1.jar:IO输入输出流组件,主要完成文件的读写功能;
- commons-lang3-3.1.jar:commons-lang是一个很有用的开源包,它弥补了Java API在提供的基本处理方法上的不足;
- commons-lang3-X.X.X.jar: as from version 2.3.3 Struts 2 bases on Commons Lang 3, but there are still external dependencies that base on Commons Lang.
- commons-logging-1.1.x.jar:ASF出品的日志包,Struts2框架使用这个日志包来支持Log4J和JDK1.4+的日志记录(如果不想显示日志的话,不需要导入)。
二、 编写Struts2的配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!
DOCTYPE
struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<
struts
>
<
constant
name
=
"struts.devMode"
value
=
"true"
></
constant
>
<
constant
name
=
"struts.i18n.encoding"
value
=
"utf-8"
></
constant
>
<
package
name
=
"struts"
namespace
=
"/"
extends
=
"struts-default"
>
<
default-action-ref
name
=
"test"
></
default-action-ref
>
<
global-results
>
<
result
name
=
"success"
>/success.jsp</
result
>
<
result
name
=
"error"
>/error.jsp</
result
>
</
global-results
>
<
action
name
=
"test"
class
=
"com.test.action.TestAction"
>
<
result
name
=
"index"
>/index.jsp</
result
>
</
action
>
</
package
>
</struts
三、 在web.xml中加入Struts2 MVC框架启动配置1234567891011121314151617181920212223<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
web-app
version
=
"3.0"
xmlns
=
"http://java.sun.com/xml/ns/javaee"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<
display-name
></
display-name
>
<
welcome-file-list
>
<
welcome-file
>index.jsp</
welcome-file
>
</
welcome-file-list
>
<
filter
>
<
filter-name
>struts2</
filter-name
>
<
filter-class
>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>struts2</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
</
web-app
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
web-app
version
=
"3.0"
xmlns
=
"http://java.sun.com/xml/ns/javaee"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<
display-name
></
display-name
>
<
welcome-file-list
>
<
welcome-file
>index.jsp</
welcome-file
>
</
welcome-file-list
>
<
filter
>
<
filter-name
>struts2</
filter-name
>
<
filter-class
>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>struts2</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
</
web-app
>
四、 编写TestAction类:123456789101112131415161718192021package
com.test.action;
import
com.opensymphony.xwork2.ActionSupport;
public
class
TestAction
extends
ActionSupport {
private
static
final
long
serialVersionUID = 1L;
public
String success() {
return
SUCCESS;
}
public
String error() {
return
ERROR;
}
public
String index() {
return
"index"
;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package
com.test.action;
import
com.opensymphony.xwork2.ActionSupport;
public
class
TestAction
extends
ActionSupport {
private
static
final
long
serialVersionUID = 1L;
public
String success() {
return
SUCCESS;
}
public
String error() {
return
ERROR;
}
public
String index() {
return
"index"
;
}
}
四、 最后编写三个页面index.jsp、success.jsp、error.jsp就OK了!
0 0
- Struts2搭建过程
- struts2 hibernate搭建过程
- struts2 搭建过程
- Struts2+Spring2.5+Hibernate3搭建过程
- struts2项目搭建过程遇到的问题反思
- 自己搭建struts2+spring+hibernate+c3p0数据库连接池过程
- 在eclipse中搭建struts2框架的详细过程
- 在eclipse中搭建struts2框架的详细过程
- Struts2搭建
- 搭建struts2
- Struts2搭建
- struts2搭建
- struts2搭建
- struts2搭建
- struts2搭建
- Struts2搭建
- 搭建一个struts2.3.4.1+spring3.1.1+hibernate3实现登录过程
- ssh框架搭建详细过程-struts2.3.14+spring4.0.0+hibernate4.3.0
- 二叉树 之 中序遍历 (不使用栈和递归)
- OA报账规范(出差专用)
- 个人学习-java-static关键字
- ubuntu14.04 busybox编译问题 make[1]:*** [menuconfig] Error 1
- centos6.7安装python2.7.11
- Struts2搭建过程
- 深入浅出解析OpenFlow
- 戒掉这七种思维方式,才能走向真正成熟
- java volatile关键字(及使用场景)
- 使用Filter解决乱码问题
- SQLserver2000还原数据库
- iOS 经典书总结
- SmartWeatherAPI_Lite_WebAPI C# 获取key加密
- selenium2.0帮助文档