码迷,mamicode.com
首页 > 其他好文 > 详细

struts 找不到action 的可能原因

时间:2017-10-26 23:06:22      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:struts

struts版本2.5.13,配置如下


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>
    <package name="app" namespace="/" extends="struts-default">
        <action name="userAction_*" class="web.actions.UserAction" method="{1}">
            <result>/success.jsp</result>
        </action>
    </package>

</struts>


访问 http://localhost/userAction_add 提示无法找action


HTTP Status 404 - There is no Action mapped for namespace [/] and action name [userAction_add] associated with context path [].
type Status report
message There is no Action mapped for namespace [/] and action name [userAction_add] associated with context path [].
description The requested resource is not available.
Apache Tomcat/7.0.82


struts为了安全,限制了Action被调用的方法,如下配置可正常访问:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>
    <package name="app" namespace="/" extends="struts-default">
        <global-allowed-methods>regex:.*</global-allowed-methods> <!-- 方法一 -->
        <action name="userAction_*" class="web.actions.UserAction" method="{1}">
            <result>/success.jsp</result>
            <allowed-methods>regex:.*</allowed-methods> <!-- 方法二 -->
        </action>
    </package>

</struts>
标签<global-allowed-methods>和<allowed-methods>中可是使用regex:开头的正则表达式,来表示允许被执行的Action方法,regex:.*表示任何方法都可以被调用;
也可以将允许被调用的方法名放入其中,多个方法用逗号隔开,如:add,delete

本文出自 “田书培” 博客,请务必保留此出处http://tianshupei.blog.51cto.com/1105157/1976527

struts 找不到action 的可能原因

标签:struts

原文地址:http://tianshupei.blog.51cto.com/1105157/1976527

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!