struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://structs.apache.org/dtds/struts-2.0.dtd"><struts>
<package name="struts2" extends="struts-default">
<action name="login" class="com.liang.cn.LoginAction">
<result name="success">/success.jsp</result>
<result name="failure">/failure.jsp</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
login.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"%><html>
<body>
<form action="login.action" method="post">
用户名:
<input type="text" name="username">
<br>
密码:
<input type="password" name="userpassword">
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
异常
HTTP Status 404 - /lianghao/login.action--------------------------------------------------------------------------------type Status reportmessage /lianghao/login.actiondescription The requested resource (/lianghao/login.action) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.18
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://structs.apache.org/dtds/struts-2.0.dtd"><struts>
<package name="struts2" extends="struts-default">
<action name="login" class="com.liang.cn.LoginAction">
<result name="success">/success.jsp</result>
<result name="failure">/failure.jsp</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
login.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"%><html>
<body>
<form action="login.action" method="post">
用户名:
<input type="text" name="username">
<br>
密码:
<input type="password" name="userpassword">
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
异常
HTTP Status 404 - /lianghao/login.action--------------------------------------------------------------------------------type Status reportmessage /lianghao/login.actiondescription The requested resource (/lianghao/login.action) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.18
加上 namespace=“/”
楼主的问题是action提交的路径不对导致无法找到对应的action
楼主项目的名称是什么名字
是lianghao吗?
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
public class LoginAction {
private String username;
private String userpassword; public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getUserpassword() {
return userpassword;
} public void setUserpassword(String userpassword) {
this.userpassword = userpassword;
}
public String execute(){
loginCheck lc=new loginCheck();
if(lc.isLogin(getUsername(),getUserpassword())){
ActionContext.getContext().getSession().put("login","true");
return "success";
}
else{
return "failure";
}
}}
<action name="login" class=""> <result></result>
</action>
name的属性是不是login
<package name="struts2" namespace="/" extends="struts-default">试试如果不行 :<action name="login" class="com.liang.cn.LoginAction" method="execute">试试...