用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - jsp代码库

广东海洋大学体育馆管理系统 源代码

2013-02-09 作者: 小蜜锋举报

[jsp]代码库

package com.gym.user.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gym.model.UserModel;
import com.gym.user.service.impl.UserServiceImpl;
import com.gym.utils.CheckOnline;
import com.gym.utils.Constant;
import com.gym.utils.Md5;

public class UserAction extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 * 
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request
	 *            the request send by the client to the server
	 * @param response
	 *            the response send by the server to the client
	 * @throws ServletException
	 *             if an error occurred
	 * @throws IOException
	 *             if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");

		String action = request.getParameter("action");

		// 检查用户是否在线
		if (!CheckOnline.isUserOnline(request)) {
			response.sendRedirect("../login.html");// 不在线,跳转到登录页面
			return;
		}

		String userId = request.getSession().getAttribute("uId").toString();

		UserServiceImpl userServiceImpl = new UserServiceImpl();

		if (action == null) { // 显示个人中心首页

			UserModel userModel = userServiceImpl.queryUserInfoById(userId);
			List userList = new ArrayList();
			userList.add(userModel);

			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/usercenter/index.jsp");
			request.setAttribute("userList", userList);
			dispatcher.forward(request, response);
		} else if (action.equals("alterinfo")) { // 显示修改个人信息页面

			UserModel userModel = userServiceImpl.queryUserInfoById(userId);
			List userList = new ArrayList();
			userList.add(userModel);

			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/usercenter/alterinfo.jsp");
			request.setAttribute("userList", userList);
			dispatcher.forward(request, response);

		} else if (action.equals("resetpwd")) { // 显示修改密码页面

			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/usercenter/resetpwd.jsp");

			dispatcher.forward(request, response);

		} else if (action.equals("mybook")) {

			UserModel userModel = new UserModel();
			userModel.setuId((String) request.getSession().getAttribute("uId"));

			List myGroundBookList = userServiceImpl.queryMyBook(userModel);

			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/usercenter/mybook.jsp");
			request.setAttribute("myGroundBookList", myGroundBookList);
			dispatcher.forward(request, response);

		} else if (action.equals("myrent")) {

			UserModel userModel = new UserModel();
			userModel.setuId((String) request.getSession().getAttribute("uId"));

			List myEquipmentRentList = userServiceImpl.queryMyRent(userModel);

			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/usercenter/myrent.jsp");
			request.setAttribute("myEquipmentRentList", myEquipmentRentList);
			dispatcher.forward(request, response);

		} else {

			RequestDispatcher dispatcher = request
					.getRequestDispatcher("/error.jsp");

			dispatcher.forward(request, response);

		}

	}

	/**
	 * The doPost method of the servlet. <br>
	 * 
	 * This method is called when a form has its tag value method equals to
	 * post.
	 * 
	 * @param request
	 *            the request send by the client to the server
	 * @param response
	 *            the response send by the server to the client
	 * @throws ServletException
	 *             if an error occurred
	 * @throws IOException
	 *             if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");

		String action = request.getParameter("action");

		// 检查用户是否在线
		if (!CheckOnline.isUserOnline(request)) {
			response.sendRedirect("../login.html");
			return;
		}

		String userId = request.getSession().getAttribute("uId").toString();

		UserServiceImpl userServiceImpl = new UserServiceImpl();
		UserModel userModel = new UserModel();

		if (action == null) {

		} else if (action.equals("alter")) { // 执行修改个人信息动作

			userModel.setuId(userId);
			userModel.setuEmail(request.getParameter("email"));
			userModel.setuIdCard(request.getParameter("idcard"));
			userModel.setuPhone(request.getParameter("phone"));
			userModel.setuName(request.getParameter("name"));

			switch (userServiceImpl.alterUserInfo(userModel)) {
			case Constant.SUCCESS:
				request.getSession()
						.setAttribute("uName", userModel.getuName()); // 更新session

				response.sendRedirect("../success.jsp");
				break;

			case Constant.ERROR:
				response.sendRedirect("../error.jsp?errorCode="
						+ Constant.ERROR);
				break;

			default:
				break;
			}

		} else if (action.equals("resetpwd")) { // 执行修改密码动作

			userModel.setuId(userId);
			String oldPwd = request.getParameter("oldpwd");
			String newPwd1 = request.getParameter("newpwd1");
			String newPwd2 = request.getParameter("newpwd2");

			switch (userServiceImpl.alterUserPwd(userModel, oldPwd, newPwd1,
					newPwd2)) {
			case Constant.SUCCESS:
				request.getSession()
						.setAttribute("uName", userModel.getuName()); // 更新session
				request.getSession().setAttribute("uId", userModel.getuId()); // 更新session

				response.sendRedirect("../success.jsp");
				break;

			case Constant.ERROR:
				response.sendRedirect("../error.jsp?errorCode="
						+ Constant.ERROR);
				break;

			case Constant.USERPWDERROR:
				response.sendRedirect("../error.jsp?errorCode="
						+ Constant.USERPWDERROR);
				break;

			case Constant.PASSWORDDIFFER:
				response.sendRedirect("../error.jsp?errorCode="
						+ Constant.PASSWORDDIFFER);
				break;

			default:
				break;
			}

		}

	}
}

[代码运行效果截图]


广东海洋大学体育馆管理系统 源代码

[源代码打包下载]




网友评论    (发表评论)

共22 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...