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

按着正确的(基于ssh)工程修改后发生404错误,代码贴出求帮助!
[color=#FF0000][/color]LoginAction

Java code

package cn.tmen.action;

import cn.tmen.action.base.UserBaseAction;
import cn.tmen.domain.Administrator;
import cn.tmen.domain.Student;
import cn.tmen.domain.Teacher;

import static cn.tmen.service.UserService.LOGIN_ADM;
import static cn.tmen.service.UserService.LOGIN_STU;
import static cn.tmen.service.UserService.LOGIN_TEA;

public class LoginAction extends UserBaseAction {
    
    //定义一个常量作为学生登录成功的Result名
    private final String STU_RESULT = "stu";
    //定义一个常量作为教师登录成功的Result名
    private final String TEA_RESULT = "tea";
    //定义一个常量作为管理员登录成功的Result名    
    private final String ADMIN_RESULT = "admin";    
    private Student stu;
    private Teacher tea;
    private Administrator admin;
    //处理登录后的提示信息
    private String tip;
    
    private String name;
    private String pass;
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public Student getStu() {
        return stu;
    }

    public void setStu(Student stu) {
        this.stu = stu;
    }

    public Teacher getTea() {
        return tea;
    }

    public void setTea(Teacher tea) {
        this.tea = tea;
    }

    public Administrator getAdmin() {
        return admin;
    }

    public void setAdmin(Administrator admin) {
        this.admin = admin;
    }

    public String getTip() {
        return tip;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    public String execute() throws Exception {
        
        // ActionContext ctx = ActionContext.getContext();
        //
        // String name = (String) ctx.getSession().get("name");
        // String pass = (String) ctx.getSession().get("pass");
        
        int result = user.validLogin(getName(), getPass());
        
        if(result==LOGIN_STU){
            setTip("您已经成功登录系统");
            return STU_RESULT;
        }
        else if(result == LOGIN_TEA){
            setTip("您已经成功登录系统");
            return TEA_RESULT;
        }
        else if(result == LOGIN_ADM){
            setTip("您已经成功登录系统");
            return ADMIN_RESULT;
        }
        else {
            setTip("用户名与密码不匹配");
            return ERROR;
        }
    }

}



Java code

package cn.tmen.action.base;

import cn.tmen.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

public class UserBaseAction extends ActionSupport {

    protected UserService user;

    public UserService getUser() {
        return user;
    }

    public void setUser(UserService user) {
        this.user = user;
    }
}




struts.xml
Java code

<?xml version="1.0" encoding="GBK"?>
<!-- 指定Struts2配置文件的DTD信息 -->
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">
<!-- Struts2配置文件的根元素 -->
<struts>
    <!-- 配置了系列常量 -->
    <constant name="struts.custom.i18n.resources" value="resource"/>
    <constant name="struts.i18n.encoding" value="GBK"/>
    <constant name="struts.devMode" value="true"/>
    
    <package name="default" extends="struts-default">
    
    
    <!-- 定义处理登录系统的Action -->
    <action name="processLogin"
        class="cn.tmen.action.LoginAction">
        <result name="input">/WEB-INF/content/login.jsp</result>
        <result name="stu">/WEB-INF/content/student/index.jsp</result>
        <result name="tea">/WEB-INF/content/teacher/index.jsp</result>
        <result name="admin">/WEB-INF/content/administrator/index.jsp</result>
        <result name="error">/WEB-INF/content/login.jsp</result>        
    </action>
    </package>
    
</struts>