【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集

Result学习笔记(三)带參数的结果集

第一部分:代码

//前端
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
	<title>Insert title here</title>
</head>
	<body>
	<ol>
		<li><a href="user/user?type=1">传參数</a></li>
	</ol>
	</body>
</html>
//web.xml
<struts>
    <constant name="struts.devMode" value="true" />
    <package name="user" namespace="/user" extends="struts-default">

	    <action name="user" class="com.struts2.user.action.UserAction">
	    	<result type="redirect">/user_success.jsp?t=${type}</result>
	    </action>
    </package>
</struts>
//类包
package com.struts2.user.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
	private int type;

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	@Override
	public String execute() throws Exception {
		return "success";
	}
}
//展示
</head>
	<body>
		User Success!
		from valuestack: <s:property value="t"/><br/>
		from actioncontext: <s:property value="#parameters.t"/>
		<s:debug></s:debug>
	</body>
</html>

第二部分:分析

1.<li><a href="user/user?type=1">传參数</a></li>,链接訪问user命名空间里面的user action,并对action传递參数type = 1;
2.<package name="user" namespace="/user" extends="struts-default">
	  <action name="user" class="com.struts2.user.action.UserAction">
		    <result type="redirect">/user_success.jsp?t=${type}</result>
	  </action>
  </package>
  <result type="redirect">/user_success.jsp?t=${type}</result>

目的:

跟据配置文件构造user action对象,并进行设置參数。由client发出请求后,由web.xml的配置文件构造UserAction对象时,请求中出传递的数值会传递到构造的对象中。注意:一次request仅仅有一个值栈.

result要求<result type="redirect">/user_success.jsp?t=${type}</result>,要求重定向到到user_success.jsp,并要求去除

action中的type值。当中type="redirect"表示是client跳转,

3.from valuestack: <s:property value="t"/><br/>				//从值栈取值
  from actioncontext: <s:property value="#parameters.t"/>	<span style="white-space:pre">	</span>//从actioncontext取值
时间: 2024-08-03 16:12:25

【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集的相关文章

【web开发学习笔记】Structs2 Result学习笔记(一)简单介绍

Structs2 Result学习笔记(一)简单介绍 问题一 <struts> <constant name="struts.devMode" value="true" /> <package name="resultTypes" namespace="/r" extends="struts-default"> <action name="r1"

【web开发学习笔记】Structs2 Result学习笔记(二)动态结果集

Result学习笔记(二) - 动态结果集 动态结果 一定不要忘了为动态结果的保存值设置set get方法 第一部分:代码 //前端 <% String context = request.getContextPath(); %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional

【web开发学习笔记】Structs2 Result学习笔记(三)带参数的结果集

Result学习笔记(三)带参数的结果集 第一部分:代码 //前端 <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030" /> <title>Insert title here</title> </head> <body> <ol> <li><a href="

Java Web开发及应用软件方向的学习计划

从接触计算机以来,一直抱有很浓厚的兴趣.我并不擅长与人交际,与机器对话可能更有性格方面的优势.虽然我很想做出一些改变,但总得需要时间和历练,暂时也只能这样了~ 一直很向往代码的神秘,在梦之站待过两年时间后更是对程序猿的生活抱有幻想,我觉得我适合做这件事情,也很有兴趣.中途我去为考研准备了一段时间,但后来我发现我对读研似乎没有很大的愿望,不是因为考研难,只是遵循了自己真正的想法.没有更高的学历,又出身一个不太牛逼的一本,将来的生活是无法预测的,我根本不确定是否能像某人说得那样走向成功.但现实如此,

Web开发中获取Spring的ApplicationContext的三种方式

在 WEB 开发中,可能会很少需要显示的获得 ApplicationContext 来得到由 Spring 进行管理的某些 Bean, 今天我就遇到了,在这里和大家分享一下, WEB 开发中,怎么获取 ApplicationContext 一       要想怎么获取 ApplicationContext, 首先必须明白 Spring 内部 ApplicationContext 是怎样存储的.下面我们来跟踪一下源码 首先:从大家最熟悉的地方开始 Java代码   <listener> <

Java Web开发: Tomcat中部署项目的三种方法

web开发,在tomcat中部署项目的方法: 注意大小写 1.在conf目录中新建Catalina\localhost目录,在该目录中新建一个xml文件,名字可以随意取,只要和当前文件中的文件名不重复就行了,改xml文件的内容为: <Context path="/qxmobile"  docBase="/usr/local/webroot/qxmobile" reloadable="false"  debug="0" p

全端Web开发 使用JavaScript与Java 阅读笔记

计算机科学领域只有两大难题:缓存失效和命名. REST(Representational State Transfer)技术,他建议一种Web服务消息传递的风格. 第一章:因变而变 企业家总在寻求变化,他们适应变化,并把它当作一种机遇. J2EE和JSP经过完善变成了JEE和JSF. 现代的客户端-服务器架构里,服务器更大程度上负责相应客户端的请求,提供资源的访问方式(通常使用XML 和JSON交换信息).在过去的服务器驱动模型中,页面(和与之相关的数据)都在服务器端生成完毕,一起返回客户端在浏

【JAVA学习】“-Xmx1024m -Xms1024m -Xmn512m -Xss256k”——Java执行參数(转)

年轻代 年老代概念 http://jefferent.iteye.com/blog/1123677 JVM的堆的内存, 是通过以下面两个參数控制的 -Xms 最小堆的大小, 也就是当你的虚拟机启动后, 就会分配这么大的堆内存给你 -Xmx 是最大堆的大小 当最小堆占满后,会尝试进行GC,假设GC之后还不能得到足够的内存(GC未必会收集到全部当前可用内存),分配新的对象,那么就会扩展堆,假设-Xmx设置的太小,扩展堆就会失败,导致OutOfMemoryError错误提示. 实际上,细节不止于此, 

可变參数学习笔记

一.什么是可变參数 我们在C语言编程中有时会遇到一些參数个数可变的函数,比如printf()函数,其函数原型为: int printf( const char* format, ...); 它除了有一个參数format固定以外,后面跟的參数的个数和类型是可变的(用三个点"-"做參数占位符),实际调用时能够有下面的形式: printf("%d",i); printf("%s",s); printf("the number is %d ,s