Package demo.servlet

Source Code of demo.servlet.ProfileServlet

package demo.servlet;

import java.io.IOException;

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

import demo.model.User;

/**
* Servlet implementation class ProfileServlet
*/
public class ProfileServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProfileServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
                                                                                  throws ServletException,
                                                                                  IOException {
        // TODO Auto-generated method stub
        //验证会话是否是登录状态,如果是没有登录,则跳转到登录页面去;否则,取出用户信息进行展示
        User user = (User) request.getSession().getAttribute("user");
        if (user == null) {
            //未登录,跳转到登录页面去
            response.sendRedirect("login");
            return;
        }
        String accessToken =(String)request.getSession().getAttribute("access_token");
        if(accessToken==null){
            response.sendRedirect("login");
            return;
        }
        RequestDispatcher welcomeDispatcher = request.getRequestDispatcher("/views/profile.jsp");
        welcomeDispatcher.forward(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
                                                                                   throws ServletException,
                                                                                   IOException {
        // TODO Auto-generated method stub
    }

}
TOP

Related Classes of demo.servlet.ProfileServlet

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.