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:com.wuliu.controller.Login.java

@RequestMapping("/login.html")
public String login(@RequestParam(value = "username") String username,
        @RequestParam(value = "password") String password, HttpServletRequest request) {
    if (username.equals(this.username) && password.equals(this.password)) {
        HttpSession session = request.getSession();
        if (session == null) {
            session = request.getSession(true);
        }//from  w  w w.  j a va  2  s. c o  m
        session.setAttribute("__USER__", username);
        return "redirect:member.html";
    } else {
        return "redirect:loginpage.html";
    }
}

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

/**
 * <p>Redirect to LINE Login Page</p>
 *///from   w  w  w  . j  a v a  2s .c o  m
@RequestMapping(value = "/gotoauthpage")
public String goToAuthPage(HttpSession httpSession) {
    final String state = CommonUtils.getToken();
    httpSession.setAttribute(LINE_WEB_LOGIN_STATE, state);
    final String url = lineAPIService.getLineWebLoginUrl(state);
    return "redirect:" + url;
}

From source file:org.openmrs.module.phrjournal.web.controller.JournalController.java

@RequestMapping(value = "/module/phrjournal/journal", method = RequestMethod.GET)
public void getEntry(@RequestParam(value = "patientId", required = false) Integer patientId,
        @RequestParam(value = "id", required = false) Integer id,
        @RequestParam(value = "search", required = false) String searchText,
        @RequestParam(value = "displayAll", required = false) String displayAll, HttpServletRequest request) {
    HttpSession session = request.getSession();
    session.setAttribute("hasPermission", true);
    session.setAttribute("searching", false);
    User user = Context.getAuthenticatedUser();
    Person per = null;//from w  w  w  .j av a2s  . c o  m
    if (patientId == null) {
        patientId = (Integer) session.getAttribute("patientId");
    }
    if (patientId == null) {
        per = user.getPerson();
    } else {
        per = Context.getPatientService().getPatient(patientId);
        session.setAttribute("patientId", patientId);
    }

    if (id != null) {
        List<JournalEntry> entries = new ArrayList<JournalEntry>();
        JournalEntry entry = Context.getService(JournalEntryService.class).getJournalEntry(id);
        List<JournalEntry> comments = Context.getService(JournalEntryService.class).findComments(entry);
        entries.add(entry);
        entries.addAll(comments);
        if (hasPermission(user, patientId)) {
            session.setAttribute("entries", entries);
        } else {
            session.setAttribute("hasPermission", false);
        }
    } else if (searchText != null && !searchText.trim().equals("") && displayAll == null) {
        List<JournalEntry> entries = ((JournalEntryService) Context.getService(JournalEntryService.class))
                .findEntries(searchText, per, true);
        addMissingParents(entries);
        session.setAttribute("entries", entries);
        session.setAttribute("searching", true);
    } else {
        List<JournalEntry> entries = Context.getService(JournalEntryService.class).getJournalEntryForPerson(per,
                true);
        addMissingComments(entries);
        session.setAttribute("entries", entries);
    }
}

From source file:com.happyuno.controller.StartGame.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 *///from w w w .j  a v a  2s .  c om
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.setContentType("text/html;charset=utf-8");
    request.setCharacterEncoding("utf-8");

    //?tableId
    String tableId = (String) request.getParameter("tableId");

    System.out.println(tableId);
    //?userId
    String userId = (String) request.getSession().getAttribute("userId");

    //
    ServletContext application = request.getSession().getServletContext();
    HashMap<Integer, GameTable> gameTableMap = (HashMap<Integer, GameTable>) application
            .getAttribute("gameTableMap");

    String resultMessage = "??";

    //User??Player
    ArrayList<Player> players = new ArrayList<Player>();

    int tindex = Integer.parseInt(tableId);
    GameTable gt = gameTableMap.get(tindex);
    ArrayList<User> userList = gt.getUserList();

    resultMessage = "??";
    //????
    gt.setStateStart(true);
    System.out.println(userList.size() + "changdu");
    for (int i = 0; i < userList.size(); i++) {
        //Playerid,nameUser?
        System.out.println(i + "position");
        String curUserId = ((User) userList.get(i)).getId();
        System.out.println("UserId" + curUserId);
        int cUserId = Integer.parseInt(curUserId);
        String curUserName = ((User) userList.get(i)).getName();
        Player curPlayer = new Player(cUserId, curUserName);
        players.add(curPlayer);
    }
    gt.getCurrentGame().initGame(players);

    HttpSession session = request.getSession();
    session.setAttribute("tableId", tindex);
    session.setAttribute("players", players);
    session.setAttribute("curPlayerId", Integer.parseInt(userId));

    //
    application.setAttribute("gameTableMap", gameTableMap);

    //tableMap?
    application.setAttribute("tatoNum", gameTableMap.size());

    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/table.jsp");
    dispatcher.forward(request, response);

}

From source file:com.happyuno.controller.JoinGameTable.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=utf-8");
    request.setCharacterEncoding("utf-8");

    //?/*www.  j  a  v a  2 s .co m*/
    String tableId = (String) request.getParameter("tableId");
    //      int tableId =Integer.parseInt(request.getSession().getAttribute("tableId").toString());

    //      String setNum = request.getParameter("setNum").trim();

    //      
    ServletContext application = request.getSession().getServletContext();
    HashMap<Integer, GameTable> gameTableMap = (HashMap<Integer, GameTable>) application
            .getAttribute("gameTableMap");

    //?ID user
    String userId = (String) request.getSession().getAttribute("userId");
    maindeal md = new maindeal();
    List dbUserList = md.query("from User as u where u.id='" + userId + "'");
    User curUser = (User) dbUserList.get(0);

    //
    String resultMessage = "?";
    int index = Integer.parseInt(tableId);
    System.out.println(index);
    //
    GameTable gametable = gameTableMap.get(index);
    if (gametable == null) {
        System.out.println("true");
    }

    int defiNum = gametable.getDefiNum();

    //
    if (gametable.isStateStart() == false) { //?
        if (gametable.getUserList().size() < defiNum) { //??
            if (!gametable.getUserList().contains(curUser)) {
                gametable.getUserList().add(curUser);
            }
            resultMessage = "??";
        } else {
            resultMessage = "???";
        }
    } else {
        resultMessage = "????";
    }

    //
    application.setAttribute("gameTableMap", gameTableMap);

    //??
    HttpSession session = request.getSession();
    session.setAttribute("tableId", index);
    session.setAttribute("userList", gameTableMap.get(index).getUserList());

    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/waiting.jsp");
    dispatcher.forward(request, response);

    //      PrintWriter out = response.getWriter();
    //      out.print("ID");
    //      out.println(userId);
    //      out.print("?:");
    //      out.println(resultMessage);
    //      out.print("?");
    //      out.println(gametable.getUserList().size());

}

From source file:org.covito.kit.web.springmvc.controller.BaseController.java

/** 
 * ?session/*from  w  w  w.j a v a2s  .  com*/
 * <p>??</p>
 *
 * @author  covito
 * @param request
 * @param paramString
 * @param paramObject
 */
protected void setSessionAttribute(HttpServletRequest request, String paramString, Object paramObject) {
    HttpSession session = request.getSession(false);
    if (session != null) {
        session.setAttribute(paramString, paramObject);
    }
}

From source file:org.openmrs.module.clinicalsummary.web.controller.upload.UploadSummariesController.java

@RequestMapping(method = RequestMethod.POST)
public String processSubmit(final @RequestParam(required = true, value = "password") String password,
        final @RequestParam(required = true, value = "summaries") MultipartFile summaries,
        final HttpServletRequest request) {
    if (Context.isAuthenticated()) {
        if (!ServerUtil.isCentral()) {
            try {
                String filename = WebUtils.prepareFilename(null, null);
                log.info("Creating zipped file: " + filename);
                File encryptedPath = OpenmrsUtil
                        .getDirectoryInApplicationDataDirectory(Constants.ENCRYPTION_LOCATION);
                String encryptedFilename = StringUtils
                        .join(Arrays.asList(filename, TaskConstants.FILE_TYPE_ENCRYPTED), ".");
                OutputStream encryptedOutputStream = new FileOutputStream(
                        new File(encryptedPath, encryptedFilename));
                FileCopyUtils.copy(summaries.getInputStream(), encryptedOutputStream);
                validate(filename, password);
                upload(filename, password);
            } catch (Exception e) {
                log.error("Unable to process uploaded documents.", e);
                HttpSession session = request.getSession();
                session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
                        "Unable to validate upload parameters. Please try again.");
                return "redirect:" + request.getHeader("Referer");
            }/* www . j a  v a 2s .  c  o  m*/
        }
    }
    return null;
}

From source file:edu.lafayette.metadb.web.authentication.Login.java

private void setUpSession(HttpSession session, String username, String project) {
    if (session.isNew()) {
        session.setAttribute(Global.SESSION_USERNAME, username);
        session.setAttribute(Global.SESSION_PROJECT, project);
        session.setAttribute(Global.SESSION_BINDER, new SessionBinder());
    }//from w w w . java  2 s  .c o  m
    if (session.getAttribute(Global.SESSION_USERNAME) == null)
        session.setAttribute(Global.SESSION_USERNAME, username);
    if (session.getAttribute(Global.SESSION_PROJECT) == null)
        session.setAttribute(Global.SESSION_PROJECT, project);
    if (session.getAttribute(Global.SESSION_BINDER) == null)
        session.setAttribute(Global.SESSION_BINDER, new SessionBinder());
}

From source file:com.bs.loginBean.LoginBean.java

@Autowired
public String doLogincgeck() {
    String status = new LoginDao().checkLogin(username, password);
    if (status.toLowerCase().equalsIgnoreCase("bm") && status != null && status != "") {
        String bm = new LoginDao().findEmpId(username, password);
        HttpSession session = LoginUtil.getSession();
        //            session.setAttribute("username", username);
        session.setAttribute("status", bm);
        return "bm";
    } else if (status.toLowerCase().equalsIgnoreCase("dataentry") && status != null && status != "") {
        String dataentry = new LoginDao().findEmpId(username, password);
        HttpSession session = LoginUtil.getSession();
        //            session.setAttribute("username", username);
        session.setAttribute("status", dataentry);
        return "dataentry";
    } else if (status.toLowerCase().equalsIgnoreCase("user") && status != null && status != "") {
        String user = new LoginDao().findEmpId(username, password);
        HttpSession session = LoginUtil.getSession();
        //            session.setAttribute("username", username);

        session.setAttribute("status", user);
        return "user";
    } else if (status.toLowerCase().equalsIgnoreCase("Exception") && status == null) {
        return "contact";
    } else {// w w w .  ja v  a 2 s .  c om
        return "try";
    }
}

From source file:com.baomidou.framework.aop.ResubmitAspect.java

/**
 * <p>//w w w .  j a v  a 2s  .co  m
 * ?? token
 * </p>
 */
public void generate(ProceedingJoinPoint joinPoint, HttpServletRequest request, HttpSession session,
        String tokenFlag) throws Throwable {
    String uuid = UUID.randomUUID().toString();
    session.setAttribute(tokenFlag, uuid);
    request.setAttribute(PARAM_TOKEN, uuid);
    joinPoint.proceed();
}