Package com.nevernote.login

Source Code of com.nevernote.login.LoginServlet

package com.nevernote.login;


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

import org.springframework.context.support.GenericXmlApplicationContext;

import com.nevernote.domain.Users;
import com.nevernote.service.UsersService;


/**
* Servlet implementation class LoginServlet
*/
public class LoginServlet extends HttpServlet {

  private static final long serialVersionUID = 8379761632383399763L;

  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {

    HttpSession session = request.getSession();
    session.setMaxInactiveInterval(-1);

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context.xml");
    ctx.refresh();

    UsersService usersService = ctx.getBean("usersService", UsersService.class);
    //validate user and return user object
    Users userSession = usersService.loginCheck(request.getParameter("un"), request.getParameter("pw"));
 
    if(userSession != null && !userSession.getId().equals("root")){
      session.setAttribute("userSession", userSession);
      response.sendRedirect("ClientDashServlet");
    } else if (userSession != null && userSession.getId().equals("root")) {
      session.setAttribute("userSession", userSession);
      response.sendRedirect("AdminDashServlet");
    } else {
      response.sendRedirect("invalidLogin.jsp");
    }
  }
}
TOP

Related Classes of com.nevernote.login.LoginServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.