zoukankan      html  css  js  c++  java
  • MVC框架Struts2学习笔记(2):Action详解

    Action中的默认值

     如果没有指定Action.默认是ActionSupport

     如果没有指定的method。默认的是action中的execute()方法。

    如果没有指定的result 的name属性。默认的是success.

    <action name="test">
                
    <result>/page/hello.jsp</result>
            
    </action>


     Action视图转发方式

     1、从定向到特定的视图---redirect

    通过result的type属性设置:

    代码
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd"
    >

    <struts>
        
    <package name="papaya" namespace="/test" extends="struts-default">
            
    <action name="hello" class="com.papaya.action.HelloAction" method="execute">
                
    <result name="success" type="redirect">/page/hello.jsp?userName=${userName}</result>
            
    </action>
        
    </package>
    </struts>


     其中的userName=${userName}来自Action com.papaya.action.HelloAction中的属性userName.

     2、重定向到Action  ---redirectAction

    代码
    <package name="redirectActionP">
            
    <action name="redirectAction">
                
    <result>
                    
    <param name="actionName">hello</param>
                    
    <param name="namespace">/test</param>
                
    </result>
            
    </action>
        
    </package>


     其中的redirectAction Action将重定向到命名空间/test下的hello这个Action.

    对于重定向的如果重定向的Action没有和自己在一个package下的时候,设置 result的时候必须设置命名空间namespace和actionName属性。

    Action属性的注入

     在Action标签xianmia

    <param name="userName">daidu</param>


  • 相关阅读:
    hdu 1199 Color the Ball 离散线段树
    poj 2623 Sequence Median 堆的灵活运用
    hdu 2251 Dungeon Master bfs
    HDU 1166 敌兵布阵 线段树
    UVALive 4426 Blast the Enemy! 计算几何求重心
    UVALive 4425 Another Brick in the Wall 暴力
    UVALive 4423 String LD 暴力
    UVALive 4872 Underground Cables 最小生成树
    UVALive 4870 Roller Coaster 01背包
    UVALive 4869 Profits DP
  • 原文地址:https://www.cnblogs.com/daidu/p/1768662.html
Copyright © 2011-2022 走看看