(4)ResultType
来源:互联网 发布:淘宝店铺域名怎么设置 编辑:程序博客网 时间:2024/06/01 13:24
<package name="ResultType" namespace="/r" extends="struts-default"> <action name="login" class="com.action.UserAction" > <result>/login.jsp</result> </action> <!-- result元素定义中,可以使用Action的execute方法运行之后的数据 --> <action name="welcome" class="com.action.UserAction"> <result>/${folder}.jsp</result><!-- 在execute中,可以返回不同的字符串(必须是Action中private属性),使得指定jsp位置的字符串是活动,而不是固定的。 下一个页面可以取到上一个请求对象(Action)里面的值--> </action> <action name="welcome1" class="com.action.UserAction"> <result type="redirect">/${folder}.jsp?username=${username}</result><!-- 下一个页面不会取到上一个请求对象的值,如果要传值,可以采用get的方式传参 该参数会存放在值栈的Stack Context的parameters中 --> </action> <action name="welcome2" class="com.action.UserAction"> <result name="toSecond" type="chain">secondAction</result><!-- 在实际开发中,比如servlet开发中,一个请求被servlet处理后,不是直接产生响应,而是将 这个请求传递给下一个servlet中,多个servlet处理完后,才会产生响应。类似struct中,一个请求被一个Action处理后,也不是立刻产生响应,要经多个Action 才会产生响应,这时就需要chain。所以chain的作用:用来将Action执行完后连接到另一个Action中继续执行,新的Action可以使用上一个Action中的ActionContext --> <!-- <param name="namespace">其他package的namespace</param> --><!-- 也就是chain链接的action是可以跨包的 --> </action> <action name="secondAction" class="com.action.secondAction"> <result>/welcome.jsp</result><!-- 最终在值栈中:Value Stack Contents中有两个Action --> </action> <!-- 注意:在上面的chain中,<result>secondAction<result>不能写传递参数,因为它对应的是action名称 --> <action name="r1" > <result type="dispatcher"><!-- 在struct2中,把result当做实现mvc模型中的视图技术,在struct2中,可以使用多种视图技术,如jsp、freemarker、velocity、jfreechart 在jsp视图中,type=dispatcher用的最多。在这个ResultType的实现中,调用了Java.servlet.RequestDispatcher类中的forward方法,也就是对RequestDispatcher 的一个在封装 --> /r1.jsp </result> </action> <!-- 上面的地址栏写http://localhost:8080/struct_ResultType/r/r1,就能访问到了r2.jsp页面 --> <!-- dispatcher:服务器端跳转,客户端不知道已经调到另外一个页面,这个页面返回到客户端 redirect:客户端发一个请求,然后在服务端redirect,相当于将此地址返回客户端,客户端发一个请求到redirect地址 --> <action name="r2"> <result type="redirect"><!-- 在这个ResultType的实现中,它包装的是Http.ServletResponse类的sendRedirect方法--> 的一个在封装 /r2.jsp </result> </action> <!-- 上面的地址栏写http://localhost:8080/struct_ResultType/r/r2 因为是redirect 最终地址栏显示的是http://localhost:8080/struct_ResultType/r2.jsp --> <action name="r3"> <result type="chain"><!-- 用于把相关的几个action连接起来,完成共同的功能 --> r1<!-- 不要写/ --> </result> </action> <!-- 上面地址栏显示的是http://localhost:8080/struct_ResultType/r/r3【请求也是这个】 --> <action name="r4"> <result type="redirectAction"> r2 </result> </action> <!-- 上面地址栏显示的是http://localhost:8080/struct_ResultType/r2.jsp 写的地址:localhost:8080/struct_ResultType/r/r4 --> </package>
阅读全文
0 0
- (4)ResultType
- JavaEE_Mybatis_SpringMVC_Mybatis_lesson11_一对一关联映射(ResultMap/ResultType)
- mybatis之resultType resultMap(一)
- Struts2-ResultType-4-带参数的结果集
- mybatis进阶(2)--一对一查询(使用resultType)
- Mybatis - 高级映射 (复习,数据表分析,一对一 之 resultType )
- Struts2-ResultType-2-全局结果集(Global_Results)
- Struts2-ResultType-3-动态结果集(dynamic_Results)
- mybatis-查询(自动封装得resultType)-12
- struts2-resultType
- MyBatis学习总结(13)——Mybatis查询之resultMap和resultType区别
- MyBatis学习笔记(五)输入(parameterType)与输出(resultType、resultMap)映射
- Mybatis中的resultType和resultMap(mybatis执行ddl语句和特殊sql语句)
- 【Mybatis从0到1-010】一对一查询(resultType和resultMap)
- WebWork 自定义resultType
- webwork转静态resultType
- struts-plugin resulttype 参数
- Struts2源码浅析-ResultType
- java中接口
- python生成器
- 二维list 无法转为二维的numpy.array?
- gitlab使用总结
- Maven和Gradle对比
- (4)ResultType
- github 入门,如何上传本地项目到github托管
- 7-10 QQ帐户的申请与登陆(25 分)
- 01 REST框架原始写法,与表单Form类似,实例
- 面向对象概念精解
- JAVA基础学习第五讲
- 【LeetCode】135.Candy(hard)解题报告
- Installation failed with message Failed to finalize session : INSTALL_FAILED_INTERNAL_ERROR.
- docker