j2ee mysql struts_j2ee 整合 struts2.3.4

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添加

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

4.配置struts.xml

1)struts.xml方在src下

2)struts.xml中添加如下配置

/p>

"http://struts.apache.org/dtds/struts-2.0.dtd">

/success.jsp

/failure.jsp

3)编写LoginAction类

packagecom.web;importcom.opensymphony.xwork2.ActionSupport;public class LoginAction extendsActionSupport{public String message ="Hello Word";privateString username;privateString passowrd;public String execute() throwsException {

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配置如下:

/p>

"http://struts.apache.org/dtds/struts-2.0.dtd">

说明:

为action包

如果你action类在 com.web下,那么value="web"

如图:

2a1b6e22bf3e1438a67bb92b9bd8511f.png

为你的jsp模板放在WebRoot下的哪个位置,如果为WebRoot的根目录下,value='/',如果为WebRoot的xxx文件夹下,则value='/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

等来访问了

该配置经本人测试成功,如您出现不成功的情况,请检查是否出现包冲突。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值