日期:2014-05-20  浏览次数:20876 次

structs2 配置 action不能访问
我自己写了一个structs2 可是不能访问action啊 请帮我看看哪里出错了
web-inf 目录下src/action 有一个LoginAction.java的类文件 代码如下
Java code

package action;
public class LoginAction 

{
   
    private String username;
    private String password;
    
    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;
    }
    public String execute () throws Exception
    {
        if (getUsername().equals("admin")&&getPassword().equals("123"))
        {
            return("success");
        }
        else
        {
            return("error"); 
        }
    }

}





WEF-INF\classes 下有个structs.xml 内容如下
Java code

<?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>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">
        <action name="Login" class="action.LoginAction">
          <result name="error">error.jsp</result>
          <result name="success">welcome.jsp</result>
        </action>
    </package>

  

</struts>




另外写了error.jsp 和welcom.jsp

web-inf 下有web.xml 代码如下
Java code

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app 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"
    version="2.4">
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


</web-app>



整个工程叫MyProject 
在这个目录下有login.jsp 可以正常访问 是个登陆界面 代码如下 点登陆的时候访问action 说404 为什么啊
Java code

<%@ page language="java" contentType="text/html;charset=GBK"%>
<html>
<head>
<title>登陆页面</title>
</head>
<body>
<form action="Login.action" method="post">
<table align="center">
<caption><h3>用户登陆</h3></caption>
<tr>
<td>用户名:<input type="text" name="username"/></td>
</tr>
<tr>
<td>
密&nbsp;&nbsp;码:<input type="text" name="password"/>
</td>
</tr>
<tr align="center">
<td clospan="2">
<input type="submit" value="登陆"/><input type="reset" value="重填"/>
</td>
</tr>
</table>
</form>
</body>
</html>