<struts>
<package name="struts2" extends="struts-default">
<action name="login" class="com.struts2.action.LoginAction">
<result name="init">/jsp/login.jsp</result>
<result name="success">/jsp/login_success.jsp</result>
<result name="failure">/jsp/login_failure.jsp</result>
</action>
</package>
</struts>想必熟悉struts2的人,都熟悉这段代码
我发现,我尝试拿掉
<package name="struts2" extends="struts-default">
程序会报错还有,因为加了package
我发现这个
http://localhost:8989/CsStruts/struts2/login.action?flag=0和
http://localhost:8989/CsStruts/login.action?flag=0二者只相差个struts2
都能正确到达对应的action类既然这样的话,为什么要加package哦?

解决方案 »

  1.   

    package的name属性并没有配置命名空间,package节点的namespace属性才是设置命名空间的,
    如果没有设置该属性的话,namespace=“”。
    所有楼主的这个action的正确方法路径应该是http://localhost:8989/CsStruts/login.action
    但为什么http://localhost:8989/CsStruts/struts2/login.action这个路径也能访问到呢?
    这就要跟struts2的action的搜索顺序有关了,当前访问http://localhost:8989/CsStruts/struts2/login.action这个路径的时候,
    会先寻找命名空间为/struts2的namespace,当然是找不到的,这个时候就会去工程的根路径下找
    这个时候是可以找的到的,所有还是能访问到,
    http://localhost:8989/CsStruts/struts2/xx/xx/login.action这个路径还是能访问到。楼主你可以试下