Struts应用出现的错误及解决方法:There is no Action mapped for namespace / and action name login
来源:互联网 发布:达内软件测试学院 编辑:程序博客网 时间:2024/06/05 04:23
PO主是J2EE的初学者,在学习到Struts部分时,PO主建立了一个模拟登录的Web Project来练手。PO主用的开发环境是MyEclipse8.5,服务器为tomcat6.0。但却出现了一个让PO主很纠结的错误:There is no Action mapped for namespace / and action name login,期间查找了很多资料,很高兴,最后能解决了,现在把它写出来跟大家分享一下,也作为自己的一个学习笔记。
以下是PO主建立Struts应用的过程.
1.打开MyEclipse8.5,新建一个Web Project,取名为Struts2Demo_2;
2.为该project添加Struts支持,即右击项目-->myeclipse-->add Struts capabilities....之后,struts specification选择struts2.1,URL pattern选择/*。
至此,添加Struts支持完成,系统会生成一个struts.xml配置文件。该文件已经配置好struts2的核心Filter。
3.WebRoot文件下建立文件loginJSP,在新建立的loginJSP下建立login1.jsp,welcome.jsp,error.jsp文件
4.打开login1.jsp文件,编写如下:
<body> <s:form name="form1" action="login1" method="post" > <s:textfield name="username" label="用户名"></s:textfield> <s:textfield name="password" label="密码"></s:textfield> <s:submit label="登录"></s:submit> </s:form> </body>
5.打开welcome.jsp,编写如下:
<body> <h1>欢迎,${username }</h1> </body>
6.打开error.jsp,编写如下:
<body> 用户名或密码不对! </body>
7.编写LoginAction类,该类继承与ActionSupport类
package com.ssh.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {private String username;private String password;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String execute(){System.out.println("LoginAction.execute()......");System.out.println("username:"+username+",password:"+password);if(username.equalsIgnoreCase("xnn")&&password.equalsIgnoreCase("123")){return "succ";}else{return "fail";}}}
8.修改配置文件struts.xml,如下:(package是struts的子元素)
<pre name="code" class="html"><package name="tom" extends="struts-default"namespace="/"> <action name="login1" class="com.ssh.action.LoginAction"> <result name="succ">/loginJSP/welcome.jsp</result> <result name="fail">/loginJSP/error.jsp</result> </action> </package>
9.部署该应用,然后启动服务器,在浏览器中输入:http://localhost:8080/Struts2Demo_2/loginJSP/login1.jsp
运行结果是:There is no Action mapped for namespace / and action name login1.
结果方案是:修改struts.xml文件,namespace修改为namespace="/test",并且<s;form>中添加属性namespace="/test"
然后重新部署,结果就出来了.
运行成功!
产生这个错误的原因是:是因为配置文件没找到。首先,检查一下你的struts.xml是否在classes 文件夹下查找路径:“安装Tomcat 的路径”\webapps\“你工程的名称”\WEB-INF\classes。其次,检查其中内容 是否正确,每一个属性都要检查,注意拼写错误!!!(通常struts.xml是myeclipse自动生成的,一般不会出现文件名错误的问题)。最后,如果jsp页面没用<s:form>的话 形式应该是这样:<form action="login1.action" > ,如果jsp页面用的是<s:form >形式 那应该是:<s:form name ="form1" action ="login1" namespace="/test">
注意:
form 标签 没有namespace属性
s:form 标签 有namespace属性
以上就是整个问题出现和解决的过程。
0 0
- Struts应用出现的错误及解决方法:There is no Action mapped for namespace / and action name login
- struts2种出现的There is no Action mapped for namespace [/] and action name 错误
- IDEA配置Struts2出现There is no Action mapped for namespace [/] and action name [login]
- 彻底解决STRUTS2 错误There is no Action mapped for namespace / and action name login
- ssh web项目出现错误There is no Action mapped for namespace [/] and action name [login] associate解决办法
- There is no Action mapped for namespace / and action name login.的解决
- There is no Action mapped for namespace [/] and action name [login] associat...问题的另一个思路
- 关于struts2总是报There is no Action mapped for namespace / and action name login错误的一点经验
- struts 配置出现错误 There is no Action mapped for namespace [/] and action name [findPage] associated with
- struts2 - There is no Action mapped for namespace [/login] and action name [login!loginInput] ...
- 关于struts的There is no Action mapped for namespace [/] and action name....异常
- Struts 中There is no Action mapped for namespace / and action name...问题的解决
- 关于 “There is no Action mapped for namespace / and action name . - [unknown location]” 的解决方法
- struts2关于"There is no Action mapped for namespace / and action name"的解决方法
- 【bug日常】struts报错: There is no Action mapped for namespace [/] and action name [login] associated ...
- There is no Action mapped for namespace /admin and action name 的一种可能错误
- There is no Action mapped for namespace / and action name"的错误
- struts2提示“There is no Action mapped for namespace [/] and action name [XXX]... ”错误的解决办法
- 14年10月英语总结
- 二十世纪最伟大的10大算法
- poj 1067 取石子游戏
- Android NDK之JNI陷阱
- c#编程:委托程序举例
- Struts应用出现的错误及解决方法:There is no Action mapped for namespace / and action name login
- 【干货】国外程序员整理的 C++ 资源大全
- M-JPEG、H.261/H.263、MPEG4、H.264这4种压缩方式有什么区别
- C 语言中的左值和右值。以及对比数组名和指针取数组元素的区别。
- C#线程间操作无效: 从不是创建控件" XX" 的线程访问它
- 数据结构(java语言描述)-- 二叉查找树的链式存储结构的实现
- SQL Server: Text was truncated or one or more characters had no match in the target code page error
- wikioi 1098 均分纸牌
- java5新特性之静态导入