action中:
public String execute() throws Exception {
User u=userService.findUserByNameAndPassword(user);
try {
u.setStudentCourseInfoList(null);
u.setTeacherCourseInfoList(null);
user.setId(u.getId());
return String.valueOf(u.getType());
/*return SUCCESS;*/
} catch (NullPointerException e) {
//json.fromObject("用户名密码错误,请重新登录!");
//this.message="错误";
JSONObject jsob = new JSONObject();
jsob.put("success", "用户名密码错误或不存在");
json = JSONObject.fromObject(jsob);
return ERROR;
}
}
配置文件中:
<action name="loginPro" class="com.lb.action.UserAction">
<result name="1">/jsp/teacher/teacher.jsp</result>
<result name="2">/jsp/student/student.jsp</result>
<result name="0">/jsp/admin/admin.jsp</result>
<!-- <result name="error">/jsp/login/fail.jsp</result>
<result type="json" name="error">
<param name="root">json</param>
</result>-->
</action>
页面中:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ taglib prefix="s" uri="/struts-tags"%>
用户登录界面
href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css">
href="${pageContext.request.contextPath}/easyui/themes/icon.css">
href="${pageContext.request.contextPath}/easyui/themes/color.css">
href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
src="${pageContext.request.contextPath}/jquery/jquery-2.1.3.min.js"> .myBackground { background: url("${pageContext.request.contextPath}/picture/background.jpg") no-repeat; background-position: 50px 50px; } .myInstitute { background: url("${pageContext.request.contextPath}/picture/logo.jpg") no-repeat; } .myBackgroundColor { background-color: #fff; }
学生信息管理系统
——光山县第二高级中学
登录
问题:学生 老师 管理员都在一个用户表,用类型区分,用户登录判断用户名和密码,判断用户类型 跳转对应页面,如果用户名或密码错误,弹出错误消息