1.拷贝/apps/struts2-blank/WEB-INF/lib中的jar到项目的lib中
各个包的介绍
Struts2依赖jar的描述:
Struts运行必要jar包:
struts2-core-2.3.1.1.jar:Struts 2框架的核心类库
xwork-core-2.3.1.1.jar:Command模式框架,WebWork和Struts2都基于xwork
ognl-3.0.3.jar:对象图导航语言(Object Graph Navigation Language), struts2框架通过其读写对象的属性
freemarker-2.3.18.jar:Struts 2的UI标签的模板使用FreeMarker编写
commons-logging-1.1.x.jar:ASF出品的日志包,Struts 2框架使用这个日志包来支持Log4J和JDK 1.4+的日志记录。
commons-fileupload-1.2.2.jar: 文件上传组件,2.1.6版本后需要加入此文件
commons-io-2.0.1.jar:传文件依赖的jar包
commons-lang-2.5.jar:对java.lang包的增强
2.在web.xml中配置Struts2的前端控制器-StrutsPrepareAndExecuteFilter
可以直接从blank的xml中复制即可
3.拷贝struts.xml文件到项目的source folder中
4.定义一个POJO类:HelloAction,并提供一个公共无参数的sayHello方法
5.在struts.xml文件中,配置HelloAction.(把HelloAction交给Struts框架管理)
配置内容见下图
6.访问Action
格式:http://ip:port/contextPath/namespaceName/actionName[.action]
http://ip:port/contextPath/crm/hello[.action]
如果想访问调到一个到一个jsp界面还需对xml进一步配置
先创建一个jsp
修改action让返回一个逻辑视图路径字符串
配置xml
访问