java action 跳转页面_关于Struts2的Action的跳转方式(跳转到JSP)(跳转到Action)...

success.jsp里:${name }---this is success.jsp

一、跳转到JSP

请求转发:http://localhost:8080/struts2action/testAction1!test1?name=tom

index.jsp里:请求转发

struts.xml里:

1 <?xml version="1.0" encoding="UTF-8"?>

2

3

4

5

6

7

12 /success.jsp

13

14

15

16

17

TestAction1.java里:

1 packagecom.xsl.action;2

3 importcom.opensymphony.xwork2.ActionSupport;4

5 public class TestAction1 extendsActionSupport {6 privateString name;7 publicString test1(){8 System.out.println("请求转发--action1--test1--name--"+name);//请求转发--action1--test1--name--tom9 //request.setAttribute("name",name);

10 return "test1";11 }12 publicString getName() {13 returnname;14 }15 public voidsetName(String name) {16 this.name =name;17 }18

19 }

success.jsp里显示:tom---this is success.jsp

重定向:http://localhost:8080/struts2action/success.jsp

index.jsp里:重定向

struts.xml里:

1 <?xml version="1.0" encoding="UTF-8" ?>

2

3

4

5

6

7

12 /success.jsp

13

14

15

16

TestAction1.java里:

1 packagecom.xsl.action;2

3 importcom.opensymphony.xwork2.ActionSupport;4

5 public class TestAction1 extendsActionSupport {6 privateString name;7 publicString test2(){8 System.out.println("重定向--action1--test2--name--"+name);//重定向--action1--test2--name--jack

9 return "test2";10 }11 publicString getName() {12 returnname;13 }14 public voidsetName(String name) {15 this.name =name;16 }17

18 }

success.jsp里显示:---this is success.jsp

二、跳转到Action

请求转发:http://localhost:8080/struts2action/testAction1!test3?name=rose

index.jsp里:请求转发

struts.xml里:

1 <?xml version="1.0" encoding="UTF-8"?>

2

3

4

5

6

7

12 testAction2_test1

13

14

15

16 /success.jsp

17

18

19

20

TestAction1.java里:

1 packagecom.xsl.action;2

3 importcom.opensymphony.xwork2.ActionSupport;4

5 public class TestAction1 extendsActionSupport {6 privateString name;7 publicString test3(){8 System.out.println("action1--test3--name--"+name);//action1--test3--name--rose

9 return "test3";10 }11 publicString getName() {12 returnname;13 }14 public voidsetName(String name) {15 this.name =name;16 }17

18 }

TestAction2.java里:

1 packagecom.xsl.action;2

3 importcom.opensymphony.xwork2.ActionSupport;4

5 public class TestAction2 extendsActionSupport {6 privateString name;7 publicString test1(){8 System.out.println("请求转发--action2--test1--name--"+name);//请求转发--action2--test1--name--rose

9 returnSUCCESS;10 }11 publicString getName() {12 returnname;13 }14 public voidsetName(String name) {15 this.name =name;16 }17 18 }

success.jsp里显示: rose---this is success.jsp

重定向:http://localhost:8080/struts2action/testAction2_test2.action

index.jsp里:重定向

struts.xml里:

1 <?xml version="1.0" encoding="UTF-8"?>

2

3

4

5

6

7

12 testAction2_test1

13 testAction2_test2

14

15

16

17 /success.jsp

18

19

20

21

TestAction1.java里:

1 packagecom.xsl.action;2

3 importcom.opensymphony.xwork2.ActionSupport;4

5 public class TestAction1 extendsActionSupport {6 privateString name;7 publicString test4(){8 System.out.println("action1--test4--name--"+name);//action1--test4--name--rain

9 return "test4";10 }11 publicString getName() {12 returnname;13 }14 public voidsetName(String name) {15 this.name =name;16 }17

18 }

TestAction2.java里:

1 packagecom.xsl.action;2

3 importcom.opensymphony.xwork2.ActionSupport;4

5 public class TestAction2 extendsActionSupport {6 privateString name;7 publicString test2(){8 System.out.println("重定向--action2--test2--name--"+name);//重定向--action2--test2--name--null9 returnSUCCESS;10 }11 publicString getName() {12 returnname;13 }14 public voidsetName(String name) {15 this.name =name;16 }17

18 }

success.jsp里显示:---this is success.jsp

相关推荐

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:数字20 设计师:CSDN官方博客 返回首页

打赏作者

weixin_39631649

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值