struts2.5框架使用通配符指定方法(常见错误)
2017-03-26 22:45
363 查看
struts2.5框架使用通配符指定方法(常见错误)
@(Java问题解决记录)struts25框架使用通配符指定方法常见错误
一问题描述
二尝试的无效方法
三各配置的具体配置
解决方法
一、问题描述
昨天使用struts2.5做人员管理系统的练习时候,遇到一个错误,怎么都解决不好,一直报错:Struts has detected an unhandled exception:
Message:There is no Action mapped for namespace [/] and action name [user_login] associated with context path [/Struts2_exec_PM].
二、尝试的无效方法
昨晚排查到1点过,都没有找到问题在哪儿。几个可能的原因都查过了:struts.xml配置文件在src下,并且服务器也部署到了WEB-INF\classes文件夹下。
三、各配置的具体配置
<?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> <constant name="struts.devMode" value="true" /> <constant name="struts.ui.theme" value="simple" /> <package name="default" namespace="/" extends="struts-default"> <action name="user_*" class="cn.lim.user.web.action.UserAction" method="{1}"> <result name="login_success">/login/home.jsp</result> <result name="login_input">/login/login.jsp</result> </action> </package> </struts>
web.xml的配置也检查过了没有问题,welcome下的index.jsp也存在。
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
jsp的form标签action的路径并没有错误。
<s:form id="loginAction_home" name="form1" action="user_login" namespace="/" target="_parent" method="post">
action类中的方法也没有问题。
public class UserAction extends ActionSupport implements ModelDriven<User>{ User user = new User(); @Override public User getModel() { // TODO Auto-generated method stub return user; } //登录操作 @InputConfig(resultName="login_input") public String login(){ return null; } }
解决方法
今天早上找到了解决方案:在struts2.3之前的版本,正常的配置就可以了,但在struts2.3版本之后,使用通配符调用方法时,内部会验证是否允许访问该方法,所以要加上:
<allowed-methods>方法名1,方法名2…</allowed-methods>
更改struts.xml后的文件:
```xml <?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> <constant name="struts.devMode" value="true" /> <constant name="struts.ui.theme" value="simple" /> <package name="default" namespace="/" extends="struts-default"> <action name="user_*" class="cn.lim.user.web.action.UserAction" method="{1}"> <result name="login_success">/login/home.jsp</result> <result name="login_input">/login/login.jsp</result> <!--添加上这个配置后问题解决--> <allowed-methods>login</allowed-methods> </action> </package> </struts>
相关文章推荐
- 【转】struts2.5框架使用通配符指定方法(常见错误)
- struts2.5框架使用通配符指定方法常见错误
- struts2.5框架使用通配符指定方法(常见错误)
- struts2.5框架使用通配符指定方法常见错误
- struts2.5框架使用通配符指定方法(常见错误)
- struts2.5框架使用通配符指定方法(常见错误)
- struts2.5框架使用通配符指定方法(常见错误)
- struts2.5框架使用通配符指定方法
- struts2.5+框架使用通配符与动态方法
- SSH配置,struts2.5使用通配符常见错误
- Struts2.5使用通配符的方式实现动态方法调用报错
- struts2.5 使用感叹号和通配符实现动态方法调用无效的问题及解决!
- struts2.5使用通配符时action指定method报错不使用通配符则正常
- Struts2.5动态方法调用action和使用通配符访问action
- 在使用struts的DispatchAction的时候出现Action找不到指定方法的错误
- Struts2.5使用通配符的方式实现动态方法调用报错
- [Struts2 框架学习] Struts2.5 通配符动态方法调用问题
- java开源框架集成常见错误之spring2.5中没有org.springframework.web.struts.DelegatingActionProxy ,使得Action不能注入到spring中
- Struts2.5版本方法无法使用通配符问题
- struts2.5 使用感叹号和通配符实现动态方法调用无效的问题及解决!