STRUTS2-错误-There-is-no-Action-mapped-for-namespace-/-and-action-name-login
已经把structs资源包中的blank项目中的jar放到eclipse的lib目录中
代码部分见下
错误信息
严重: Could not find action or result
There is no Action mapped for namespace / and action name login. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
以下为代码部分
===========================================
login.jsp
<body>
<form action="login.action" method="post">
用户名: <input type="text" name="username" > <br>
密码: <input type="password" name="password"> </br>
<input value="提交" type="submit">
</form>
<br>
</body>
===========================================
web.xml(路径在web-inf下)
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2 </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<filter-mapping>
<filter-name>struts2 </filter-name>
<url-pattern>/* </url-pattern>
</filter-mapping>
</web-app>
===========================================
structs.xml(路径在web-inf\classes下)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name="login" class="com.test.action.LoginAction" >
<result name="success">/result.jsp </result>
</action>
</package>
<!-- Add packages here -->
</struts>
===========================================
LoginAction.java
package com.test.action;
public class LoginAction {
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() throws Exception
{
return "success";
}
}
这个问题已经在网上找了一天了,也没有能解决掉,希望有人能帮忙 谢谢了!!!
上述帖子内容用得别人的,我也碰到了这个问题,至今还没解决,希望有人帮忙一下 多谢!!
你的struts2.xml放在WEB-INF下还是放在classes下.?
把struts.xml放到classes下就没事了
把struts.xml文件全部删除,重新写一次解决的这个问题。
struts的配置文件必须是struts.xml,我改成struts_login.xml了
是我自己的问题,我把bean的class文件定义路径不写错了,不是配置的问题。