面对不同种类的处理结果——result type=
Struts2中有很多不同种类的处理结果,有action也有视图文件。比较常见的情景就是我们要一个action链接到另一个action应该怎么做呢?我在这里就做了一个小例子
JSP文件内容
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title></title></head><body><!-- chain链式结果类型,从一个action跳到另一个action --><s:form action="start"><s:submit value="chain链式"/></s:form><!-- 源代码类型 --><s:form action="plainText"><s:submit value="plainText源代码"/></s:form><!-- 请求转发 --><s:form action="dispatcher"><s:submit value="dispatcher转发到JSP视图文件"/></s:form><!-- 请求重定向 --><!-- 注意:重定向和请求转发可是有区别的哦,比较明显的是URL变化 --><s:form action="redirect"><s:submit value="redirect重定向到JSP视图文件"/></s:form><!-- 请求重定向到一个action --><s:form action="redirectAction"><s:submit value="redirectAction重定向到一个Action中"/></s:form><!-- 请求重定向,可以自定义的???这里只能是英文的,我就算在xml中设置的charSet也没有用,有知道的前辈求解一下这个问题,十分感谢--><s:form action="redirect-custom"><s:textfield name="myUrl"/><s:submit/></s:form><!-- 测试全局结果,如果一个action找不到匹配 --><s:form action="login!global"><s:submit value="TestGlobal"/></s:form></body>
</html>
struts.xml文件内容
<?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.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="true" /><constant name="struts.custom.i18n.resources" value="test"/><package name="default" namespace="/" extends="struts-default"><global-results><result name="TestGlobal">/content/TestGlobal.jsp</result></global-results><action name="login" class="action.LoginAction"><result name="success">/content/success.jsp</result></action><action name="start" class="action.ActionOne"><result type="chain">end</result></action><action name="end" class="action.ActionTwo"><result>/content/success.jsp</result></action><action name="plainText"><result type="plainText"><param name="location">/content/success.jsp</param><param name="charSet">UTF-8</param></result></action><action name="dispatcher"><result type="dispatcher">/content/success.jsp</result></action><action name="redirect"><result type="redirect">/content/success.jsp</result></action><action name="redirectAction"><result type="redirectAction"><param name="actionName">TestRedirectAction</param><param name="namespace">/</param></result></action><action name="redirect-custom" class="action.RedirectCustom"><result type="redirect"><param name="location">testRedirect.action?myUrl=${myUrl}</param></result></action><action name="testRedirect" class="action.TestRedirect"><result>/content/success.jsp</result></action><action name="TestRedirectAction"><result>/content/success.jsp</result></action></package></struts>
action中的类的内容
ActionOne.java
package action;import com.opensymphony.xwork2.ActionSupport;public class ActionOne extends ActionSupport {@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubSystem.out.println("This is ActionOne");return super.execute();}
}
ActionTwo.java
package action;import com.opensymphony.xwork2.ActionSupport;public class ActionTwo extends ActionSupport {@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubSystem.out.println("This is ActionTwo");return super.execute();}
}
LoginAction.java
package action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubSystem.out.println("This is execute");return super.execute();}public String method1() throws Exception {System.out.println("This is one");return SUCCESS;}public String method2() throws Exception {System.out.println("This is two");return SUCCESS;}public String global() throws Exception {System.out.println("This is glboal()");return "TestGlobal";}
}
RedirectCustom.java
package action;import com.opensymphony.xwork2.ActionSupport;public class RedirectCustom extends ActionSupport {private String myUrl;public String getMyUrl() {return myUrl;}public void setMyUrl(String myUrl) {this.myUrl = myUrl;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubSystem.out.println("这里是RedirectCustom的execute(),接收到的myUrl为" + getMyUrl());return super.execute();}
}
TestRedirect.java
package action;import com.opensymphony.xwork2.ActionSupport;public class TestRedirect extends ActionSupport {private String myUrl;public String getMyUrl() {return myUrl;}public void setMyUrl(String myUrl) {this.myUrl = myUrl;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubSystem.out.println("这里是TestRedirect的execute(),接收到的myUrl值为:" + getMyUrl());return super.execute();}
}
呼呼~总之你做好这几个文件就好了,之后慢慢看action是如何跳转的。我先撤了
面对不同种类的处理结果——result type=相关推荐
- no result type defined for type 'dispatch'mapped
自己打算弄个webwork测试问题时候,遇到个脑瘫的问题,配了xwork之后,死活找不到action,报There is no result type defined for type 'dispat ...
- Webwork2之Action Result Type(转载)
和Webwork1.x不同,Webwork2的Action执行完后,其Result对应一个 Result Type,而这个Result Type完全可以根据具体应用或环境自己进行 定义,只需实现com ...
- 【问题解决】mybatis 类型不匹配两种解决办法 -Result type not match for select id=“selectUser“ srcType: com.kuang.pojo
问题描述: Result type not match for select id="selectUser"srcType: com.kuang.pojo.UsertargetTy ...
- MapStruct Unknown property “xx“ in result type XXX. Did you mean “null“?
build报错 Unknown property "xx" in result type XXX. Did you mean "null"? 解决办法 pom. ...
- ajax请求type种类,ajax配置项中的type与method
1. jQuery中ajax配置项中的使用type与method的区别 本质上两个配置项是没有区别的,区别在于两者出现的时间不同,type对于目前jQuery的版本全部兼容,也就是说 $.ajax({ ...
- YOLOV5报错:RuntimeError: result type Float can‘t be cast to the desired output type long int
YOLOV5训练时报错: Traceback (most recent call last): File "train.py", line 626, in <module ...
- 训练yolo时报错RuntimeError: result type Float can‘t be cast to the desired output type __int64个人解决方案
运行YOLOv5 6.1和yolor的时候,训练都没能正常运行,均出现了如下错误: AutoAnchor: 5.00 anchors/target, 1.000 Best Possible Recal ...
- 【Error Logs】YoloV5出现RuntimeError: result type Float can‘t be cast to the desired output
问题描述 在训练 yolov5做简单的识别的时候出现,错误:RuntimeError: result type Float can't be cast to the desired output ty ...
- 解决Yolov5的RuntimeError: result type Float can‘t be cast to the desired output type long int 问题
在yolov5中,直接下载github上的代码可能出现无法运行的情况,会报错 RuntimeError: result type Float can't be cast to the desired ...
最新文章
- java杂记-static
- Windows Server 2008常用优化设置
- js将数组元素随机排序的方法
- 线性规划总结3——单纯形法和对偶单纯形法
- Tomcat 启动提示未发现 APR 的解决方法
- SAP Cloud Platform Identity Authentication service
- boolean 默认_MySQL数据类型测试:BOOLEAN、TINYINT测试数据总结(第八节)
- 在sae中运行web.py应用
- 二维数组,字符串,字符数组
- autocad2007二维图画法_AutoCAD2007中文版机械制图教程
- Python数据分析-绘图-2-Seaborn进阶绘图-4-分类图
- 史上最好听的十首纯音乐推荐
- 洛谷 P5713 【深基3.例5】洛谷团队系统
- linux安装命令自动运行y,在Linux上安装Gnome Tweak以在Gnome Shell上自动启动程序
- 100道MySQL数据库经典面试题解析(有空必看)
- 《操作系统真象还原》第十四章 ---- 实现文件系统 任务繁多 饭得一口口吃路得一步步走啊(上一)
- java获取上周一_java 如何获取 上周一日期,上周末日期,本周一日期。
- 【python】之字符串格式化
- Java并发编程的艺术(推荐指数:☆☆☆☆☆☆)
- Android 伪造短信