Struts2配置默认action(首页)、配置404防止请求出错问题解决

设置默认首页:
     在配置文件Struts.xml中,找到首页处理对应的package【包】,加入:
<default-action-ref name="index" />
其中“index”就是默认的action,结果如下:
Edit
<!-- 默认命名空间 -->
<package name="default" namespace="/" extends="struts-default">

    <!-- 配置默认action -->
    <default-action-ref name="index" />
    <action name="index">
        <result>/WEB-INF/jsp/index.jsp</result>
    </action
</package>

此文老猫原创,转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/51241353

更多有关老猫的文章:http://blog.csdn.net/nthack5730




防止请求出错:
There is no Action mapped for namespace [/] and action name [] associated with context path....
在需要处理的命名空间下,加入由【*】配置的action即可。这个方法不单单能在根命名空间做处理,在任意命名空间都可以做这个处理,需要处理的就加上即可。

Edit
<!-- User命名空间 -->
<package name="User" namespace="/user" extends="struts-default">

    <!-- 配置默认action -->
    <default-action-ref name="index" />
    <action name="index">
        <result>/WEB-INF/jsp/user.jsp</result>
    </action>

    <!-- 通过通配方式跳转,防止页面地址乱请求 -->
    <!-- 只要找不到对应的action都自动跳转到index,可以再写一个404的action,自动跳转到404 -->
    <action name="*">
        <result type="redirect">index</result>
    </action>
</package>

此文老猫原创,转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/51241353

更多有关老猫的文章:http://blog.csdn.net/nthack5730




猜你喜欢

转载自blog.csdn.net/nthack5730/article/details/51241353