HTTP Status 404 - There is no Action mapped for namespace [/] and action name [product-save] associated with context path [/20161101-struts2-2].

运行:index.jsp---->input.jsp----->details.jsp,但是在input.jsp到details.jsp的时候报错误。

异常如下:

严重: Could not find action or result
/
There is no Action mapped for namespace [/] and action name [] associated with c
ontext path []. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:1
85)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsAct
ionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultA
ctionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOper
ations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilt
er(StrutsPrepareAndExecuteFilter.java:91)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler
.java:1419)
at com.bjhit.eranges.utils.SetCharacterEncodingFilter.doFilter(SetCharacterEnco
dingFilter.java:39)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler
.java:1419)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137
)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java
:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java
:1075)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:
193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:
1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135
)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHand
lerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.
java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:1
16)
at org.eclipse.jetty.server.Server.handle(Server.java:368)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpCo
nnection.java:489)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpC
onnection.java:942)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplet
e(AbstractHttpConnection.java:1004)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java
:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.
java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.j
ava:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:
608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:5
43)
at java.lang.Thread.run(Thread.java:662)

代码如下:

web.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
 3   <display-name>20161101-struts2-2</display-name>
 4
 5      <!-- 配置struts2的Filter -->
 6      <filter>
 7         <filter-name>struts2</filter-name>
 8         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 9     </filter>
10
11     <filter-mapping>
12         <filter-name>struts2</filter-name>
13         <url-pattern>/*</url-pattern>
14     </filter-mapping>
15
16 </web-app>

struts.xml:

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5
 6 <struts>
 7    <!-- package:包,struts2使用package来组织模块
 8         name属性:必须,用于被其他包引用当前包
 9         extends:当前包继承哪个包,即可继承父包的所有配置,通常情况下继承struts-default
10     -->
11
12    <package name="helloworld" extends="struts-default">
13
14          <!-- 配置一个action:一个struts2的请求就是一个action
15               name:对应一个struts2的请求的名字(对应着servletPath,但去除/和扩展名)
16               result:结果
17           -->
18          <action name="product-input">
19               <result>/WEB-INF/pages/input.jsp</result>
20          </action>
21
22          <action name="product-save" class="com.tt.struts2.helloworld.Product"
23                  method="save">
24               <result name="details">/WEB-INF/pages/details.jsp</result>
25          </action>
26
27    </package>
28
29
30 </struts>

index.jsp:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10         <!-- "product-input.action"就是servletPath -->
11         <a href="product-input.action">Product Input</a>
12 </body>
13 </html>

input.jsp:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10           <!-- "product-save.action"就是servletPath -->
11           <form action="product-save.action"  >
12
13                 ProductName:<input type="text" name="productName"/>
14                 <br><br>
15
16                 ProductDesc:<input type="text" name="productDesc"/>
17                 <br><br>
18
19                 ProductPrice:<input type="text" name="productPrice"/>
20                 <br><br>
21
22                 <input type="submit" value="Submit"/>
23                 <br><br>
24           </form>
25
26 </body>
27 </html>

details.jsp:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10                 ProductId:${productId }
11                 <br><br>
12
13                 ProductName:${productName }
14                 <br><br>
15
16                 ProductDesc:${productDesc }
17                 <br><br>
18
19                 ProductPrice:${productPrice }
20                 <br><br>
21 </body>
22 </html>

Product.java:

 1 package com.tt.struts2.helloworld;
 2
 3 public class Product {
 4     private Integer productId;
 5
 6     private String productName ;
 7     private String productDesc ;
 8     private double productPrice ;
 9
10     public String getProductName() {
11         return productName;
12     }
13     public void setProductName(String productName) {
14         this.productName = productName;
15     }
16     public String getProductDesc() {
17         return productDesc;
18     }
19     public void setProductDesc(String productDesc) {
20         this.productDesc = productDesc;
21     }
22     public double getProductPrice() {
23         return productPrice;
24     }
25     public void setProductPrice(double productPrice) {
26         this.productPrice = productPrice;
27     }
28
29     public Integer getProductId() {
30         return productId;
31     }
32     public void setProductId(Integer productId) {
33         this.productId = productId;
34     }
35
36
37     @Override
38     public String toString() {
39         return "Product [productId=" + productId + ", productName=" + productName + ", productDesc=" + productDesc
40                 + ", productPrice=" + productPrice + "]";
41     }
42
43     public String save(){
44
45         System.out.println("sava: "+this);
46         return "details";
47     }
48 }

原因分析:

猜测应该是struts.xml的问题,但是第一个product-input的action都可以正常跳转(index.jsp---->input.jsp),为什么第二个product-save(input.jsp----->details.jsp)的action无法正常呢?

二者唯一的区别就是第二个action需要利用反射调用Product类里的save( )方法。但save方法没问题,最后怀疑表单提交上的问题。

仔细看input.jsp页面,发现input.jsp里的form表单提交没有设置method,那么默认为get。

解决办法:将input.jsp里的form添加method="post"问题就解决了,但是不知道为什么会这样,具体原因还有待研究。

在网上查找的这个报错的常见原因如下:

1.struts.xml文件错误。

这种错误又分为以下几种:

1)struts.xml文件名错误。一定要注意拼写问题;

2)struts.xml文件放置路径错误。一定要将此文件放置在src目录下。编译成功后,要确认是否编译到classes目录中;

3)struts.xml文件内容错误:启动页面一定要是自己工程里有的jsp文件。

<welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
     </welcome-file-list>

如果你在Eclipse工程的WebContent文件夹下没有这个index.jsp文件,也会报同样的错误。
    比如我自己定义了一个login.jsp文件,放在WebContent文件夹下,就写成
    <welcome-file>login.jsp</welcome-file> 
    把login.jsp文件放在WEB-INF下自定义的jsp文件夹下,就写成
    <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file>

2.表单提交页面的错误

比如上面我的错误。

时间: 2024-08-04 15:29:57

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [product-save] associated with context path [/20161101-struts2-2].的相关文章

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [Action!Method]错误解决

按照书本上的Struts2的例子,运行会出现错误: HTTP Status 404 - There is no Action mapped for namespace [/] and action name [sayHelloAction!sayStruts2] ... 貌似在struts.xml中配置action的method不会出错,而直接在jsp中写“Action!Method.action”就会报错. 搜索许久没有发现解决办法,后来发现第二种写法叫做“DMI”,会产生安全隐患,在stru

Struts2-tomcat报错:There is no Action mapped for namespace / and action

HTTP Status 404 - There is no Action mapped for namespace / and action name first. type Status report message There is no Action mapped for namespace / and action name first. description The requested resource is not available. Apache Tomcat/6.0.37 解

There is no Action mapped for namespace [/] and action name [xx] associated with context path...

好久没用Struts了,今天练了一个简单的应用,出现了一些意外的问题,由于这种原因一直报404 首先我的目录结构是这样子滴 web.xml中是这样配置的 <web-app> <display-name>Archetype Created Web Application</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.a

关于Struts2中的错误:例如There is no Action mapped for namespace / and action name product-input.

            在配置struts.xml 文件时,会出现    There is no Action mapped for namespace / and action name ....    意思是没有product-input的映射文件或者是命名空间       出现这样的错误的原因后:     做如下检查:           1: 把struts.xml中的namespace="/"改成namespace=""或者去除,使用默认的命名空间. 2:

There is no Action mapped for namespace / and action name 通配符的问题

之前看了一些struts2的视频. 现在复习了下 struts2.发现了这个问题 网上的说的解决办法大都没提到这个问题,1%的文章提到了新版本的struts中 method的问题 There is no Action mapped for namespace / and action name XXX http://localhost:8080/Struts2Learn/loginAction_login.action 原因不详. 解决办法: 通配符  *  的使用方法中. struts-2.5

There is no Action mapped for namespace [/] and action name [Login] associated with context path [/e

近期学习web开发时,就遇到这个令人头疼的问题. 百度谷歌了N遍,最终在博客http://blog.csdn.net/liu578182160/article/details/17266879中找到了问题的根源. 开发环境:win7 32位旗舰版,jdk1.7_45,jre7,eclipse4.3.1 JavaEE版,tomcat 7.0.42,struts2.3.16.3 问题出如今web.xml配置 原web.xml: <?xml version="1.0" encoding

struts2中错误There is no Action mapped for namespace [/] and action name [] associated with context path

1 There is no Action mapped for namespace [/] and action name [] associated with context path [/Struts2_0300_Action2]. - [unknown location] 2 at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185) 3 at org.apache.struts2.i

struts2 : There is no Action mapped for namespace / and action name

2015.07.13 晚 学习搭建SSI 框架,用到struts2 ,启动后访问指定login.action报错 There is no Action mapped for namespace / and action name 查找原因,struts.xml 没有被找到. 解决方法 1 : 在web.xml中指定struts.xml 的位置 解决方法 2 : 将struts.xml 放在src根目录下,web.xml中不需配置struts.xml的地址. 总结 ,对框架各配置文件之间作用不了解

There is no Action mapped for namespace [/] and action name [LoginAction_home] associ

使用struts2框架产生的问题: index.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8"%> <jsp:forward page="/login/login.jsp"></jsp:forward> login.jsp: <%@ page language="java" pageEncodin