Example usage for javax.servlet.http HttpSession setAttribute

List of usage examples for javax.servlet.http HttpSession setAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession setAttribute.

Prototype

public void setAttribute(String name, Object value);

Source Link

Document

Binds an object to this session, using the name specified.

Usage

From source file:LocaleSessionServlet.java

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

    HttpSession userSession = request.getSession();
    if (userSession.isNew()) {
        userSession.setAttribute("userLocale", request.getLocale());
    }/*from  w  w  w.  j  a  v  a2  s.c o m*/
}

From source file:com.feilong.controller.TestController.java

@RequestMapping("/helloworld1")
public String test1(HttpServletRequest request, HttpSession session, HttpServletResponse response) {

    session.setAttribute("name", "?");
    request.setAttribute("name", "");
    session.getServletContext().setAttribute("name", "?");

    return UrlBasedViewResolver.REDIRECT_URL_PREFIX + "/index";
}

From source file:com.liferay.portal.action.LoginAction.java

public static void addSessionAttributes(HttpSession ses, HashMap map) {
    if (map == null)
        return;//www .j  a  va 2 s . c om
    Set keys = map.keySet();
    if (keys == null)
        return;

    Iterator iter = keys.iterator();
    while (iter.hasNext()) {
        String name = (String) iter.next();
        ses.setAttribute(name, map.get(name));
    }
}

From source file:com.linecorp.sample.login.application.controller.APIController.java

private void setAccessToken(HttpSession httpSession, AccessToken accessToken) {
    httpSession.setAttribute(WebController.ACCESS_TOKEN, accessToken);
}

From source file:com.panlj.system.action.LoginAction.java

@RequestMapping("login")
public String loginForm(@ModelAttribute("user") User user, HttpServletRequest request,
        HttpServletResponse response, Model model) {
    User userTemp = userDao.findByUsername(user.getUsername());
    if (userTemp != null) {
        String pwdTemp = userTemp.getPassword();

        //Sring ????*************************************************
        Md5PasswordEncoder md5 = new Md5PasswordEncoder();
        String pwd = md5.encodePassword(user.getPassword(), user.getUsername());
        if (pwdTemp.equals(pwd)) {
            System.out.println("??" + user.getUsername() + ",?!");
            //UserSession
            UserSession userSession = new UserSession();
            userSession.setName(userTemp.getName());
            userSession.setUsername(userTemp.getUsername());
            HttpSession session = request.getSession();
            session.setAttribute("userSession", userSession);
            try {
                response.sendRedirect("/system/main/index");
            } catch (IOException e) {
                e.printStackTrace();//from  w w w. ja v  a 2 s.  c  o m
            }
        }
    }
    return "login";
}

From source file:com.starr.smartbuilds.controller.AuthController.java

@RequestMapping(method = { RequestMethod.GET }, value = "/exit")
public void getExit(Model model, HttpServletRequest req, HttpServletResponse resp) throws IOException {
    HttpSession session = req.getSession();
    session.setAttribute("user", null);
    resp.sendRedirect("../");
}

From source file:MyServlet.java

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    String account = req.getParameter("account");
    String password = req.getParameter("password");
    String pin = req.getParameter("pin");

    if (!allowUser(account, password, pin)) {
        out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
        out.println("<BODY>Your login and password are invalid.<BR>");
        out.println("You may want to <A HREF=\"/login.html\">try again</A>");
        out.println("</BODY></HTML>");
    } else {//from   w w w  .j  a  v a 2 s  . co  m
        out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
        out.println("<BODY>Your login and password are valid.<BR>");
        out.println("</BODY></HTML>");
        HttpSession session = req.getSession();
        session.setAttribute("logon.isDone", account); // just a marker object

        try {
            String target = (String) session.getAttribute("login.target");
            if (target != null) {
                res.sendRedirect(target);
                return;
            }
        } catch (Exception ignored) {
        }

        //res.sendRedirect("/");
    }
}

From source file:net.groupbuy.service.impl.RSAServiceImpl.java

@Transactional(readOnly = true)
public RSAPublicKey generateKey(HttpServletRequest request) {
    Assert.notNull(request);/*from   ww w.  j av a  2 s  .  c o  m*/
    KeyPair keyPair = RSAUtils.generateKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
    HttpSession session = request.getSession();
    session.setAttribute(PRIVATE_KEY_ATTRIBUTE_NAME, privateKey);
    return publicKey;
}

From source file:org.openmrs.module.openhmis.inventory.web.controller.SettingsControllerBase.java

@RequestMapping(method = RequestMethod.POST)
public void submit(HttpServletRequest request, Settings settings, Errors errors, ModelMap model)
        throws IOException {
    ModuleSettings.saveSettings(settings);

    HttpSession session = request.getSession();
    session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "openhmis.inventory.settings.saved");

    render(model, request);/* w  w w  .  ja v a  2s  .c o m*/
}

From source file:LoginHandler.java

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    String account = req.getParameter("account");
    String password = req.getParameter("password");
    String pin = req.getParameter("pin");

    if (!allowUser(account, password, pin)) {
        out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
        out.println("<BODY>Your login and password are invalid.<BR>");
        out.println("You may want to <A HREF=\"/login.html\">try again</A>");
        out.println("</BODY></HTML>");
    } else {/*from ww w .j  a  v a2  s . c o  m*/
        // Valid login. Make a note in the session object.
        HttpSession session = req.getSession();
        session.setAttribute("logon.isDone", account);
        // Try redirecting the client to the page he first tried to access
        try {
            String target = (String) session.getAttribute("login.target");
            if (target != null) {
                res.sendRedirect(target);
                return;
            }
        } catch (Exception ignored) {
        }

        // Couldn't redirect to the target. Redirect to the site's home page.
        res.sendRedirect("/");
    }
}