报错: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:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<display-name>20161101-struts2-2</display-name> <!-- 配置struts2的Filter -->
<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> </web-app>
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<!-- package:包,struts2使用package来组织模块
name属性:必须,用于被其他包引用当前包
extends:当前包继承哪个包,即可继承父包的所有配置,通常情况下继承struts-default
--> <package name="helloworld" extends="struts-default"> <!-- 配置一个action:一个struts2的请求就是一个action
name:对应一个struts2的请求的名字(对应着servletPath,但去除/和扩展名)
result:结果
-->
<action name="product-input">
<result>/WEB-INF/pages/input.jsp</result>
</action> <action name="product-save" class="com.tt.struts2.helloworld.Product"
method="save">
<result name="details">/WEB-INF/pages/details.jsp</result>
</action> </package> </struts>
index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- "product-input.action"就是servletPath -->
<a href="product-input.action">Product Input</a>
</body>
</html>
input.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- "product-save.action"就是servletPath -->
<form action="product-save.action"> ProductName:<input type="text" name="productName"/>
<br><br> ProductDesc:<input type="text" name="productDesc"/>
<br><br> ProductPrice:<input type="text" name="productPrice"/>
<br><br> <input type="submit" value="Submit"/>
<br><br>
</form> </body>
</html>
details.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
ProductId:${productId }
<br><br> ProductName:${productName }
<br><br> ProductDesc:${productDesc }
<br><br> ProductPrice:${productPrice }
<br><br>
</body>
</html>
Product.java:
package com.tt.struts2.helloworld;
public class Product {
private Integer productId;
private String productName ;
private String productDesc ;
private double productPrice ;
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDesc() {
return productDesc;
}
public void setProductDesc(String productDesc) {
this.productDesc = productDesc;
}
public double getProductPrice() {
return productPrice;
}
public void setProductPrice(double productPrice) {
this.productPrice = productPrice;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
@Override
public String toString() {
return "Product [productId=" + productId + ", productName=" + productName + ", productDesc=" + productDesc
+ ", productPrice=" + productPrice + "]";
}
public String save(){
System.out.println("sava: "+this);
return "details";
}
}
原因分析:
猜测应该是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(注意:html提交表单的方式默认为get)。

解决办法:将input.jsp里的form添加method="post"问题就解决了。
那么get请求和post请求有何区别呢?见http://www.cnblogs.com/TTTTT/p/6650117.html
在网上查找的这个报错的常见原因如下:
1.struts.xml文件错误。
这种错误又分为以下几种:
1)struts.xml里配置action的class时,全类名要写正确。
2)struts.xml文件名错误。一定要注意拼写问题;
3)struts.xml文件放置路径错误。一定要将此文件放置在src目录下。编译成功后,要确认是否编译到classes目录中;
4)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.表单提交页面的错误
比如上面我的错误。
报错:HTTP Status 404 - There is no Action mapped for namespace [/] and action name [product-save] associated with context path [/20161101-struts2-2].的更多相关文章
- 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 repor ...
- TOMCAT报错:HTTP Status 404 -
构建struts2工程师,tomcat报错: HTTP Status 404 - type Status report message description The requested resour ...
- struts2报错:There is no Action mapped for namespace [/] and action name [userAction!add]
使用struts2.3进行动态方法调用时出现: There is no Action mapped for namespace [/user] and action name [user!add] a ...
- 在IE浏览器输入测试servlet程序报:HTTP Status 404(The requested resource is not available)错
一.HTTP Status 404(The requested resource is not available)异常主要是路径错误或拼写错误造成的,请按以下步骤逐一排查: 1.未部署Web应用 2 ...
- http://localhost/ 或 http://127.0.0.1/ 报错:HTTP 404 的解决办法
一些初次接触使用 Eclipse 工具来开发 JAVA Web 工程的开发人员,可能会对 Eclipse 和 Tomcat 的绑定产生一个疑惑. 那就是 在修改了 Tomcat 的8080端口为80后 ...
- 【Solr】新建core后,启动服务访问web报错 HTTP Status 503
新建core collection2后,启动solr服务,访问solr web界面报错. HTTP Status 503 - Server is shutting down or failed to ...
- 报错HTTP Status 500 - Unable to instantiate Action
报错如下: HTTP Status 500 - Unable to instantiate Action, visitAction, defined for 'visit_toAddPage' in ...
- 报错HTTP Status 500 - The given object has a null identifier: cn.itcast.entity.Customer; nested exception is org.hibernate.TransientObjectException: The given object has a null identifier:
在使用模型驱动封装的时候,要保证表单中name属性名和类中属性名一致,否则将会报错如下: HTTP Status 500 - The given object has a null identifie ...
- 求教:Knife4jAggregationDesktop访问报错HTTP ERROR 404
(1)Windows Server 2019下面,java版本:c:\Users\WinUser01\.jdks\corretto-1.8.0_292\bin\java.exe(2)Knife4jAg ...
随机推荐
- NET中的规范标准注释(二) -- 创建帮助文档入门篇
一.摘要 在本系列的第一篇文章介绍了.NET中XML注释的用途, 本篇文章将讲解如何使用XML注释生成与MSDN一样的帮助文件.主要介绍NDoc的继承者:SandCastle. 二.背景 要生成帮助文 ...
- MVC模式与三层架构的区别
之前总是混淆MVC表现模式和三层架构模式,为此记录下. 三层架构和MVC是有明显区别的,MVC应该是展现模式(三个加起来以后才是三层架构中的UI层) 三层架构(3-tier application) ...
- poj 2777
题意:两个操作:c l r x l到r之间的颜色变成x q l r 询问l到r有多少种颜色 思路:记一个整数表示哪种颜色是否取了 这里真的是煞笔了,看到这一题第一直觉是异或,但是A^A= ...
- 如何获取EntityManager
1.在容器内部使用,使用@PersistenceContext 来注入.@PersistenceContextprivate EntityManager em;TAG================= ...
- Ubuntu中查看32还是64
安装ubuntu在pc上,不推荐在32位pc安装64位操作系统,64位pc安装32位操作系统 方法/步骤 1 按ctrl+shift+t 快捷键,打开终端,输入sudo uname --m ,按下 ...
- Android Studio Reference local .aar files
repositories { flatDir { dirs 'libs' }} dependencies { compile 'com.android.support:support-v4:22.2. ...
- 【C++ STL编程】queue小例子
STL是标准化组件,现在已经是C++的一部分,因此不用额外安装什么. #include <queue> #include <iostream> using namespace ...
- Asp.net中Json的序列化和反序列化(二)
三.JSON序列化和反序列化日期时间的处理 JSON格式不直接支持日期和时间.DateTime值值显示为“/Date(700000+0500)/”形式的JSON字符串,其中第一个数字(在提供的示例中 ...
- 动手实现自己的 STL 容器《2》---- list
1. 序: 本文参考了侯捷的 <STL 源码分析>一书,出于兴趣,自行实现了简单的 list 容器. 学习了 STL 的 list 容器的源代码,确实能够提高写链表代码的能力.其中的 so ...
- Android 学习第11课,android 实现拨打电话的功能
1. 先布局界面,界面采用线性垂直方式来布局 在layout 界面文件中 activity_main.xml 中 <LinearLayout xmlns:android="http:/ ...