zoukankan      html  css  js  c++  java
  • 【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取值




  • 相关阅读:
    Day4 0708
    Day2 0706
    两道递推公式题的解题报告
    博客还需优化
    飞行路线Luogu4568
    堆优化Dijkstra(Luogu 4779)
    2019四等奖的清明节征文
    2019四等奖的叶圣陶初稿
    Luogu P1072 Hankson的趣味题
    Loj10022 埃及分数(迭代加深搜索IDDFS)
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4492056.html
Copyright © 2011-2022 走看看