日期:2014-05-17  浏览次数:20674 次

struts2小项目出错了
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 t