zoukankan      html  css  js  c++  java
  • <s:action>的一些用法

    Action标签,顾名思义,是用来调用Action的标签,在JSP中页面中,可以具体指定某一命名空间中的某一Action。而标签的主体用于显示及渲染Actionr的处理结果。
    action标签有如下几个属性:
    id: 可选属性,作为该Action的引用ID   
    name:必选属性,指定调用Action   
    namespace:可选属性,指定该标签调用Action所属namespace   
    executeResult:可选属性,指定是否将Action的处理结果包含到本页面中.默认值为false,不包含.   

    ignoreContextParam:可选参数,指定该页面的请求参数是否需要传入调用的Action中,默认值是false,即传入参数.

    <s:action name="login" executeResult="true" namespace="/"></s:action> 

    传递参数 

    <s:action name="actinName" executeResult="true" namespace="/"> 
        <s:param name="currentPage" value="传递的值"></s:param> 
       </s:action> 

    <s:param ></s:param>是以request方式的值的,而不是以参数传值 

    所以request.getParameter("")会获取不到值 

    通过request.getAttribute("")方式可以获取 

    另外:使用<s:param ></s:param> value指代的是action定义的对象的名称,而不是一个值 

    和 <s:textfield>中的name是一个意思,所以要要传递字符串的不能把值写value中而应该写到 

    <s:param >写到这里</s:param> 


    <body>
       <s:action id="searchFunction" namespace="/" name="projectMake-Info"  executeResult="true" >
      	<s:param name="pid" value="20"></s:param>
       </s:action>
    	
      </body>

    public String Info() throws Exception{
    		ActionContext actionContext = ActionContext.getContext();
            HttpServletRequest request = (HttpServletRequest)actionContext.get(ServletActionContext.HTTP_REQUEST);     
            ConvertUtil cu =new ConvertUtil();
            
    //        pid=cu.strToInt(request.getParameter("pid") );
              pid= (Integer) request.getAttribute("pid");
            try {
            	System.out.println("访问单个项目的id:"+pid);
            	myp=pm.getProjectByPid(pid);
    		} catch (Exception e) {
    			// TODO: handle exception
    			return "infoFail";
    		}

    强制将对象转为int

    如果要获得action传过来的值,这样

     <body>
       <s:action id="searchFunction" namespace="/" name="projectMake-Info"  executeResult="false" >
      	<s:param name="pid" value="20"></s:param>
       </s:action>
    	 <s:property value="%{#searchFunction.myp.name}"/>
      </body>

    传字符串的时候要这样传

    <s:param name="lanmu">duhuimingpin</s:param>


    随便讲下getParameter和getAttribute的区别

    HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下区别:

    (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法

    (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码:

    <a   href="authenticate.jsp?username=weiqin">authenticate.jsp   </a>

    或者:

    <form   name="form1"   method="post"   action="authenticate.jsp">
        请输入用户姓名:<input   type="text"   name="username">
        <input   type="submit"   name="Submit"   value="提交">
    </form>

    在authenticate.jsp中通过request.getParameter("username")方法来获得请求参数username:

    <%   String   username=request.getParameter("username");   %>

    (3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享request范围内的数据。假定   authenticate.jsp和hello.jsp之间为转发关系。authenticate.jsp希望向hello.jsp传递当前的用户名字,   如何传递这一数据呢?先在authenticate.jsp中调用setAttribute()方法:

    <%
    String   username=request.getParameter("username");
    request.setAttribute("username",username);
    %>

    <jsp:forward   page="hello.jsp"   />

    在hello.jsp中通过getAttribute()方法获得用户名字:

    <%   String   username=(String)request.getAttribute("username");   %>
    Hello:   <%=username   %>

    从更深的层次考虑,request.getParameter()方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据。request.getParameter()方法返回String类型的数据。

    request.setAttribute()和getAttribute()方法传递的数据只会存在于Web容器内部,在具有转发关系的Web组件之间共享。这两个方法能够设置Object类型的共享数据。

    request.getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据,,   request.setAttribute()和getAttribute()只是在web容器内部流转,仅仅是请求处理阶段,这个的确是正解.

    getAttribute是返回对象,getParameter返回字符串


    request.getAttribute()方法返回request范围内存在的对象,而request.getParameter()方法是获取http提交过来的数据。



    指定方法

      目前都是一个action配置一个方法  更好的方法还没想到

    版权声明:本文为博主原创文章,未经博主允许不得转载。

    today lazy . tomorrow die .
  • 相关阅读:
    [ jquery 文档处理 replaceWith(content|fn) replaceAll(content) ] 此方法用于把所有匹配的元素替换成指定的HTML或DOM元素
    [ jquery 文档处理 wrapInner(htm|element|fnl) ] 此方法用于把所有匹配的元素的子元素(包括文本节点)使用指定的 HTML 元素来包裹
    [ jquery 文档处理 wrapAll(html|ele)) ] 此方法用于把所有匹配的元素使用指定的 HTML 元素来包裹
    [ jquery 文档处理 wrap(html|element|fn) ] 此方法用于把所有匹配的元素用其他元素的结构化标记包裹起来
    [ jquery 文档处理 insertBefore(content) before(content|fn) ] 此方法用于把所有匹配的元素插入到另一个、指定的元素元素集合的前面,实现外部插入
    [ jquery 文档处理 insertAfter(content) after(content|fn) ] 此方法用于把所有匹配的元素插入到另一个、指定的元素元素集合的后面,实现外部插入
    [ jquery 文档处理 prependTo(content) ] 此方法用于把所有匹配的元素前置到另一个、指定的元素元素集合中
    剑指 Offer 55
    剑指 Offer 54. 二叉搜索树的第k大节点 树的遍历
    剑指 Offer 52. 两个链表的第一个公共节点 哈希
  • 原文地址:https://www.cnblogs.com/france/p/4808604.html
Copyright © 2011-2022 走看看