Action的搜索顺序(Struts2搜索Action的机制)

  当访问如下链接时,

http://localhost:8080/struts2Demo/path1/path2/path3/LoginAction.action

  第一步:判断当前路径下action是否存在,如:path1/path2/path3/

  第二步:存在:则去访问相应的Action;不存在:检查上一级路径的package中是否存在action(直到默认的namespace,此处默认的namespace为"/"),重复第一步。
  第三步:如果没有则报错。

 

  文件清单:LoginAction、index.jsp、success.jsp、struts.xml、web.xml
      index.jsp
  
    <form action ="LoginAction.action" method ="post" >
            <input type= "submit" value ="测试" />
       </form>

  struts.xml

  <package name ="default" namespace ="/" extends ="struts-default" >
        <action name= "LoginAction" class="com.struts2.action.LoginAction" method ="execute" >
            <result name= "success">/success.jsp </result>
        </action>
    </package>

  LoginAction.java

  

public class LoginAction extends ActionSupport{
     public String execute (){
            String result="success" ;
            return result ;
     }
}

**************************************************************************************************

  如若转载请注明出处,谢谢。By奋斗的小蘑菇

posted @ 2015-10-15 09:49  奋斗的小蘑菇  阅读(986)  评论(0编辑  收藏  举报