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="struts" namespace="/" extends="struts-default">
<action name="login" class="com.test.LoginAction">
<result name="failure">/failure.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
===================
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="demo" version="2.4"
xmlns="http://java.sun.com/ml/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>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
======================
LoginAction.java
package com.test;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport
{
private String username;
private String password;
public String exucute() throws Exception {
if(username.equals("struts"))
return "success";
else
return "failure";
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
==================
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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="login.action" method="get" %>
用户名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br/>
<input type="submit" value="login">
</form>
</body>
</html>
不管在login.jsp页面中输入的用户名是什么,都只会跳转到success.jsp页面。在LoginAction.java中打断点,没有作用,没有经过LoginAction.java中的execute方法的处理。
问题出在哪儿了?
struts2
------解决方案--------------------
楼主写代码不小心,execute方法名写错了,所以这个action里没有execute方法,自动返回success。。