我跟着风中叶视频的第一个Struts2应用做,但是未成功。
现象:
login.jsp页面能被正常请求到,但是点击submit之后就不行了。页面错误信息:
HTTP Status 404 - There is no Action mapped for namespace / and action name login.
type Status report
message There is no Action mapped for namespace / and action name login.
description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.控制台错误信息:
2008-6-13 18:39:08 org.apache.struts2.dispatcher.Dispatcher serviceAction
严重: 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)
………………环境:
apache-tomcat-6.0.16
jdk 1.5
struts-2.0.11
myeclipse 6.0 (eclipse 3.3.2)包:
五个包。没有用更多的。Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Struts 2.0 Hello World</display-name>
<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>login.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>This is "login.jsp" page</title>
</head>
<body>
<form action="login.action" method="post">
username:
<input type="text" name="username">
<br>
password:
<input type="password" name="password">
<br>
<input type="submit" value="submit">
</form>
</body>
</html>struts.xml(在src下面,编辑之后自动拷贝到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="default" extends="struts-default"> <action name="login" class="com.ecc.struts2.action.LoginAction">
<result name="success">/result.jsp</result>
</action> </package></struts>result.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
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>This is "result.jsp" Page.</title>
</head>
<body>
username:${ requestScope.username }
<br>
password:${ requestScope.password }
<br>
</body>
</html>
请问各位大侠,该如何解决?在此感谢!
现象:
login.jsp页面能被正常请求到,但是点击submit之后就不行了。页面错误信息:
HTTP Status 404 - There is no Action mapped for namespace / and action name login.
type Status report
message There is no Action mapped for namespace / and action name login.
description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.控制台错误信息:
2008-6-13 18:39:08 org.apache.struts2.dispatcher.Dispatcher serviceAction
严重: 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)
………………环境:
apache-tomcat-6.0.16
jdk 1.5
struts-2.0.11
myeclipse 6.0 (eclipse 3.3.2)包:
五个包。没有用更多的。Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Struts 2.0 Hello World</display-name>
<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>login.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>This is "login.jsp" page</title>
</head>
<body>
<form action="login.action" method="post">
username:
<input type="text" name="username">
<br>
password:
<input type="password" name="password">
<br>
<input type="submit" value="submit">
</form>
</body>
</html>struts.xml(在src下面,编辑之后自动拷贝到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="default" extends="struts-default"> <action name="login" class="com.ecc.struts2.action.LoginAction">
<result name="success">/result.jsp</result>
</action> </package></struts>result.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
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>This is "result.jsp" Page.</title>
</head>
<body>
username:${ requestScope.username }
<br>
password:${ requestScope.password }
<br>
</body>
</html>
请问各位大侠,该如何解决?在此感谢!
ActionSupport类在com.opensymphony.xwork2.ActionSupport中。
<action name="login" class="com.ecc.struts2.action.LoginAction">
<result name="success">/result.jsp </result>
</action>
象你这样写就可以了,。
如果你没有继承ActionSupport,那么在struts.xml中必须这样写:
<action name="login.action" class="com.ecc.struts2.action.LoginAction">
<result name="success">/result.jsp </result>
</action>
<action name="login.action" class="com.ecc.struts2.action.LoginAction">
<result name="success">/result.jsp </result>
</action>
这样写的,似乎仍然出现楼主说的相同的错误,到底是哪里出错了呢?
楼主【cwxinxiang】截止到2008-07-18 13:36:46的历史汇总数据(不包括此帖):
发帖的总数量:1 发帖的总分数:20 每贴平均分数:20
回帖的总数量:2 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:1 结贴的总分数:20
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:0.00 % 无满意结分率:0.00 %
敬礼!
是不是struts。xml 文件位置放的不对呢?
web-info/classes下吗?
<struts>
<packagte name="struts2" namespace="/" extends="struts-default">
<action>...
</action>
</package>
</struts>不要漏了namespace="/"这个配置
你的struts.xml里的<package name="default" extends="struts-default"> 跟教程里的不一样。
<filter-name>struts2 </filter-name>
<url-pattern>/* </url-pattern>
</filter-mapping>
这样一来,jsp页面应该访问不到啊
一个struts2引来这么多人关注 这说明会struts2的人太多了
<package name="default" extends="struts-default" namespace="/">
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
还有,你的action代码呢?