发现无论是success 还是 input 还是其他的都 不能够返回到struts.xml中
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println(userId);
if ("学生".equals(role)) {
StudentDao studentDao=new StudentDaoImpl();
Student student =studentDao.findStudentByID(userId);
if(student == null){
System.out.println("不存在该用户");
addActionError("不存在该用户");
return this.INPUT;
}else{
if(password.equals(student.getPassword())){
Map session=ActionContext.getContext().getSession();
session.put("studentInfo", student);
return "studentSuccess";
}else {
addActionError("密码错误");
return this.INPUT;
}
}
}else{
TeacherDao teacherDao=new TeacherDaoImpl();
Teacher teacher=teacherDao.findTeacherByID(userId);
if(teacher == null){
addActionError("不存在该用户");
return this.INPUT;
}else{
if(password.equals(teacher.getPassword())){
Map session=ActionContext.getContext().getSession();
session.put("teacherInfo", teacher);
return "teacherSuccess";
}else {
addActionError("密码错误");
return this.INPUT;
}
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.i18n.encoding" value="gb2312"></constant>
<package name="struts2" extends="struts-default">
<action name="login" class="com.mon.action.LoginAction">
<result name="studentSuccess" type="chain">getRandomSubject</result>
<result name="teacherSuccess" type="redirect">/teacher/index.html</result>
<result name="INPUT">/index.jsp</result>
</action>
<action name="getRandomSubject" class="com.mon.action.GetRandomSubjectAction">
<result name="SUCCESS">/student/main.jsp</result>
</action>
</package>
</struts>
------解决方案--------------------