错误提示:HTTP Status 404 - There is no Action mapped for namespace / and action name login.
type Status reportmessage 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.
--------------------------------------------------------------------------------Apache Tomcat/6.0.20下面上代码:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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">
<display-name>re</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
struts.xml<?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="example" namespace="example" extends="struts-default">
<action name="login" class="com.re.example.loginAction">
<result name="success">/success.jsp</result>
<result name="fail">/fail.jsp</result>
</action>
</package>
</struts>loginAction.javapackage example;
public class loginAction {
private String usename;
private String password;
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setUsename(String usename) {
this.usename = usename;
}
public String getUsename() {
return usename;
}
public String execute() throws Exception{
if(getUsename().equals("admin")&&getPassword().equals("pass")){
return "success";
}
else{
return "fail";
}
}
}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=ISO-8859-1">
<title>登陆页面</title>
</head>
<body>
<form action="login" method="post">
用户:<input type="text" name="usename"/><br/>
密码:<input type="password" name="password"/><br/>
<input type="reset" value="重置"><input type="submit" value="提交"/>
</form>
</body>
</html>
type Status reportmessage 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.
--------------------------------------------------------------------------------Apache Tomcat/6.0.20下面上代码:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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">
<display-name>re</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
struts.xml<?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="example" namespace="example" extends="struts-default">
<action name="login" class="com.re.example.loginAction">
<result name="success">/success.jsp</result>
<result name="fail">/fail.jsp</result>
</action>
</package>
</struts>loginAction.javapackage example;
public class loginAction {
private String usename;
private String password;
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setUsename(String usename) {
this.usename = usename;
}
public String getUsename() {
return usename;
}
public String execute() throws Exception{
if(getUsename().equals("admin")&&getPassword().equals("pass")){
return "success";
}
else{
return "fail";
}
}
}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=ISO-8859-1">
<title>登陆页面</title>
</head>
<body>
<form action="login" method="post">
用户:<input type="text" name="usename"/><br/>
密码:<input type="password" name="password"/><br/>
<input type="reset" value="重置"><input type="submit" value="提交"/>
</form>
</body>
</html>
解决方案 »
- jsp:useBean
- 求助,性能测试时第一次的时间总是比其他的慢
- jboss+mysql+linux问题
- 新手问一个简单的jsp问题,求思路
- spring2.5.6+ jpa(hibernate3.5.1)配置dbcp数据源的小问题
- 朋友们帮忙看下这个报错啥意思!!!我无语了!这两天都快疯了!
- 急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急。。。。。报错啊,高分求解啊,
- Dom4J解析xml忽略节点大小写
- 请JAVA程序员都报上自己的MSN号码,这样可以更有效的交流!!!
- 开发实时系统采用.Net还是J2EE?
- myeclipse 格式化问题
- SSH框架中在Action中调用DAO报空指针
试试
<action name="login" class="com.re.example.loginAction">里面的path呢好久没用过Action了 不知道说的是否正确
改成:<package name="example" namespace="/example" extends="struts-default">2. 在浏览器输入url的时候要用:http://xxxx/example/login.action
改成: <form action="login" namespace='/example' method="post">
"/<App_Name>/login"
就照着Tomcat下面的例子写的都不行。
真是郁闷了。
<form action="login" method="post">
改成:
<s:form action="login" namespace='/example' method="post"> 等等...
<form action="example/login" method="post">
namespace问题,要加入url的
现在是
HTTP Status 404 - There is no Action mapped for action name login.
错误了。
Struts.xml写成了sturts.xml
彻底无语了