配置Struts2时,报没有action与form表单填写的action对应的错误。
来源:互联网 发布:long转int java 编辑:程序博客网 时间:2024/04/29 20:40
前两天自己搭建SSH过程中,当我在页面上写了一个form表单提交时,系统报了如下错误:
There is no Action mapped for namespace / and action name saveUser. - [unknown location]
当时,我一直以为是因为我页面action写的有问题,才会报这个错,仔细检查了一下页面:
<span style="color:#ff0000;"><form name="fm" action="saveUser" method="post"></span> <table> <tr> <td> 用户名: </td> <td> <input name="user.userName" type="text" /> </td> <td> 昵称: </td> <td> <input name="user.nickName" type="text" /> </td> </tr> <tr> <td> 密码: </td> <td> <input name="user.password" type="password" /> </td> <td> 邮箱: </td> <td> <input name="user.email" type="text" /> </td> </tr> <tr> <td> 性别: </td> <td> <input name="user.sex" type="radio" value="1" />男 <input name="user.sex" type="radio" value="0" />女 </td> </tr> <tr> <td> 生日: </td> <td> <input name="user.birth" type="text" /> </td> </tr> <tr> <td colspan="2"> <input type="submit" value="保存" /> <input type="button" value="取消" onclick="javascript:void(0);" /> </td> </tr> </table> </form>
struts.xml文件中:
<package name="user" namespace="/" extends="struts-default"><action name="saveUser" class="userAction" method="save"><result name="save_user">/webJsp/success.jsp</result></action></package>web.xml文件中:
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
发现都没有问题,然后想到,因为我这个SSH是参考当时公司项目搭建的,我把struts.xml文件放在里src目录下的一个struts下的子包中,然后想到这块可能会有点问题(也是在同学的提醒下),后面我把struts.xml文件单独拿出来放在src目录下,问题解决:
但是,我想,难道就办法访问,source下面,struts包中的struts.xml文件吗?因为如果是做项目的话,一般大家的struts配置文件都是一人一个的。于是,又搜了下struts.xml路径,得到的结果是肯定可以访问的,我们只需在web.xml中配置如下信息(红色部分):
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <span style="color:#ff0000;"><init-param> <param-name>config</param-name> <param-value>struts-default.xml,struts-plugin.xml,/source/struts/struts.xml</param-value> </init-param></span> </filter>
因为我的struts配置文件是放在source包下的struts子包中的,而当项目部署完以后,strus2默认加载的是web-inf下classes下的struts.xml文件,这就是为什么一开始会报“no Action mapped”错误了,当时我还以为是名字啥的写的有问题,其实根本原因是因为,struts2根本就没有加载到struts.xml配置文件,所以会报出这个错误。而我将struts配置文件放在source下时,部署完以后,struts.xml的位置是在web-inf/classes/source/struts目录下的,所以<param-value>中与之对应就可以啦!
还要注意的是如果配置了<param-name>config</param-name>参数,那么struts-defual.xml等加载文件也许要放置进来,否则将不能自动加载而报错,还有struts-plugin.xml文件,也许要放在这儿,因为struts2,2.1.6版本中,有struts-spring-plugin-2.1.6.jar(如果使用spring集成的话)有这个struts-plugin.xml文件,另外,json-plugin-0.34.jar(如过struts需要json支持)中也有这个文件。
当然,其实我们平常项目中一般都是讲struts.xml配置文件直接放在src目录下,然后其他配置文件放在同一包下,再在struts.xml文件中include这些配置文件就行了,这样struts2默认就加载了所以的配置文件。
- 配置Struts2时,报没有action与form表单填写的action对应的错误。
- 关于表单提交Form的action url 的填写
- form表单的action
- struts2找不到对应action错误的解决
- struts2的form提交时action属性的配置
- Struts2利用convention-plugin 实现零配置时Action与jsp的对应关系
- STRUTS2的Action配置
- struts2的Action配置
- struts2的action配置
- struts2的Action配置
- struts1中form表单的action配置问题
- Ajax的url与form表单的Action冲突问题
- form表单action值的相对目录与绝对目录
- 闲扯struts2-页面与action的配置!
- struts1 与struts2 Action的配置实现
- js修改form表单的action属性,commit提交后,再更改action属性。发现表单没有提交
- struts2 action跳转action 的配置方法
- 关于Form表单的action和onSubmit
- c与c++
- Linux Fedora20 配置desktop文件,将软件添加到应用程序浏览器中
- magento 负载一路飙涨记录
- Java 内部类种类及使用解析
- windows下Lua配置
- 配置Struts2时,报没有action与form表单填写的action对应的错误。
- mysql安装版一系列
- 关于使用struts2注解配置,action返回json到IE8及以下浏览器接收为undefined的问题
- hbase multiple SLF4J bindings 警告 问题解决办法
- SGU 185 Two shortest 最短路+最大流
- Java 内部类
- 利用中央气象台的天气预报API实现天气预报
- ubuntu进入root
- 重叠子问题2(15章:动态规划)。。。2014.6.1