整合 struts2.3.4
来源:互联网 发布:知乎 民贷天下 编辑:程序博客网 时间:2024/06/05 17:30
1.到官网下载 struts2.3.4
2.把lib下的(1)commons-fileupload-1.2.2(2)commons-io-2.0.1(3)commons-lang-2.4(4)commons-lang3-3.1(5)commons-logging-1.1.1(6)commons-logging-api-1.1(7)freemarker-2.3.19(8)javassist-3.11.0.GA
(9)ognl-3.0.5(10)struts2-core-2.3.4.1(11)xwork-core-2.3.4.1
这11jar拷贝到项目lib下
3.配置web.xml
web.xml添加
<filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 --> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
4.配置struts.xml
1)struts.xml方在src下
2)struts.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="main" extends="struts-default" namespace=""> <action name="login" class="com.test.LoginAction" method="execute"> <result name="loginSuccess">/success.jsp</result> <result name="loginFailure">/failure.jsp</result> </action> </package> </struts>
3)编写LoginAction类
package com.web;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{ public String message ="Hello Word"; private String username; private String passowrd; public String execute() throws Exception { System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxx"); username="1"; if (username.equals("struts2")) { System.out.println("aaaaaaaaaa"); return "success"; } else { System.out.println("dddddddddd"); return "error"; } }
public String abc(){
System.out.println("abc");
return "success";
}
public String cba(){
System.out.println("cba");
return "error";
}
}
这样 你可以可以通过 hppt://pc-xxx:8080/xxx/login.action来访问了
5、如何让struts2 实现零配置
在导入之前jar的基础上,再增加3个jar,它们分别为
1)struts2-convention-plugin-2.3.4.1
2)asm-3.3
3)asm-commons-3.3
4)web.xml在之前的配置基础上不变,改变struts.xml的配置,struts.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> <constant name="struts.convention.action.disableScanning" value="false"/> <constant name="struts.convention.classes.reload" value="true" /> <constant name="struts.convention.package.locators" value="web" /> <constant name="struts.convention.result.path" value="/" /> </struts>
说明:
<constant name="struts.convention.package.locators" value="web" /> 为action包
如果你action类在 com.web下,那么value="http://www.cnblogs.com/sunshin2012/archive/2012/09/19/web"
如图:
<constant name="struts.convention.result.path" value="/" /> 为你的jsp模板放在WebRoot下的哪个位置,如果为WebRoot的根目录下,value='http://www.cnblogs.com/',如果为WebRoot的xxx文件夹下,则value='http://www.cnblogs.com/xxx'
4)此时 模板的命名要以action的类名来命名相对于来命名,如LoginAction,则对于的user-返回的string来命名,如:
login-success.jsp
login-error.jsp
5)此时 你就可以通过 hppt://pc-xxx:8080/xxx/login.action、
hppt://pc-xxx:8080/xxx/login!abc.action、
hppt://pc-xxx:8080/xxx/login!cba.action
等来访问了
该配置经本人测试成功,如您出现不成功的情况,请检查是否出现包冲突。
1.到官网下载 struts2.3.4
2.把lib下的(1)commons-fileupload-1.2.2(2)commons-io-2.0.1(3)commons-lang-2.4(4)commons-lang3-3.1(5)commons-logging-1.1.1(6)commons-logging-api-1.1(7)freemarker-2.3.19(8)javassist-3.11.0.GA
(9)ognl-3.0.5(10)struts2-core-2.3.4.1(11)xwork-core-2.3.4.1
这11jar拷贝到项目lib下
3.配置web.xml
web.xml添加
<filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 --> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
4.配置struts.xml
1)struts.xml方在src下
2)struts.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="main" extends="struts-default" namespace=""> <action name="login" class="com.test.LoginAction" method="execute"> <result name="loginSuccess">/success.jsp</result> <result name="loginFailure">/failure.jsp</result> </action> </package> </struts>
3)编写LoginAction类
package com.web;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{ public String message ="Hello Word"; private String username; private String passowrd; public String execute() throws Exception { System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxx"); username="1"; if (username.equals("struts2")) { System.out.println("aaaaaaaaaa"); return "success"; } else { System.out.println("dddddddddd"); return "error"; } }
public String abc(){
System.out.println("abc");
return "success";
}
public String cba(){
System.out.println("cba");
return "error";
}
}
这样 你可以可以通过 hppt://pc-xxx:8080/xxx/login.action来访问了
5、如何让struts2 实现零配置
在导入之前jar的基础上,再增加3个jar,它们分别为
1)struts2-convention-plugin-2.3.4.1
2)asm-3.3
3)asm-commons-3.3
4)web.xml在之前的配置基础上不变,改变struts.xml的配置,struts.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> <constant name="struts.convention.action.disableScanning" value="false"/> <constant name="struts.convention.classes.reload" value="true" /> <constant name="struts.convention.package.locators" value="web" /> <constant name="struts.convention.result.path" value="/" /> </struts>
说明:
<constant name="struts.convention.package.locators" value="web" /> 为action包
如果你action类在 com.web下,那么value="http://www.cnblogs.com/sunshin2012/archive/2012/09/19/web"
如图:
<constant name="struts.convention.result.path" value="/" /> 为你的jsp模板放在WebRoot下的哪个位置,如果为WebRoot的根目录下,value='http://www.cnblogs.com/',如果为WebRoot的xxx文件夹下,则value='http://www.cnblogs.com/xxx'
4)此时 模板的命名要以action的类名来命名相对于来命名,如LoginAction,则对于的user-返回的string来命名,如:
login-success.jsp
login-error.jsp
5)此时 你就可以通过 hppt://pc-xxx:8080/xxx/login.action、
hppt://pc-xxx:8080/xxx/login!abc.action、
hppt://pc-xxx:8080/xxx/login!cba.action
等来访问了
该配置经本人测试成功,如您出现不成功的情况,请检查是否出现包冲突。
<filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 --> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<?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="main" extends="struts-default" namespace=""> <action name="login" class="com.test.LoginAction" method="execute"> <result name="loginSuccess">/success.jsp</result> <result name="loginFailure">/failure.jsp</result> </action> </package> </struts>
package com.web;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{ public String message ="Hello Word"; private String username; private String passowrd; public String execute() throws Exception { System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxx"); username="1"; if (username.equals("struts2")) { System.out.println("aaaaaaaaaa"); return "success"; } else { System.out.println("dddddddddd"); return "error"; } }
public String abc(){
System.out.println("abc");
return "success";
}
public String cba(){
System.out.println("cba");
return "error";
}
}
<?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> <constant name="struts.convention.action.disableScanning" value="false"/> <constant name="struts.convention.classes.reload" value="true" /> <constant name="struts.convention.package.locators" value="web" /> <constant name="struts.convention.result.path" value="/" /> </struts>
如果你action类在 com.web下,那么value="http://www.cnblogs.com/sunshin2012/archive/2012/09/19/web"
如图:
login-success.jsp
login-error.jsp
5)此时 你就可以通过 hppt://pc-xxx:8080/xxx/login.action、
- 整合 struts2.3.4
- struts2整合extremeTable
- Struts2 Spring2 整合
- dwr2与struts2整合
- Struts2整合报表JasperReports
- Struts2整合JFreeChart图表
- EJB3,Spring,Struts2整合
- struts2整合jfreechart
- Struts2与Hibernate整合
- struts2+hibernate+spring整合
- Struts2 与 Spring 整合
- urlrewriter 和 Struts2 整合
- Struts2整合FreeMarker实例
- struts2 spring hibernate 整合
- Spring struts2 hibernate 整合
- struts2整合spring步骤
- spring/struts2整合
- spring 整合struts2
- 一堂如何提高代码质量的培训课
- Java 多线程编程总结
- HTML5开发岗位猛增44% iOS增速不及Android-htm5来了
- 可能有用的小方法
- 对WM_NCHITTEST消息的了解+代码实例进行演示
- 整合 struts2.3.4
- servlet处理json
- 正则表达式对数字的判断——转
- 基于LDA模型的文本聚类研究
- 我的网龙面试经历(2013年c++程序员技术面试)
- 【工具类】AES加密和解密
- 深入研究ReentrantLock(重入锁)
- Windows Message Codes
- 二叉树中两个节点的最近公共父节点