Example usage for javax.servlet.http HttpServletRequest setAttribute

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

Introduction

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

Prototype

public void setAttribute(String name, Object o);

Source Link

Document

Stores an attribute in this request.

Usage

From source file:cn.cug.laboratory.web.BaseController.java

/**
 * ? HttpServletRequest //from   ww  w .ja  va2  s .  co m
 * @param name
 * @param value
 */
protected void setHttpServletRequestAttribute(String name, Object value) {
    HttpServletRequest request = this.getHttpServletRequest();
    request.setAttribute(name, value);
}

From source file:com.renlg.door.controller.LoginController.java

/**
 * //w  w w.  j a  va2  s .  c  om
 * @return
 */
@RequestMapping("index")
public String toIndex(HttpServletRequest request) {
    Calendar cal = Calendar.getInstance();
    LunarUtil lunar = new LunarUtil(cal);
    request.setAttribute("lunar", lunar.getDateStr());
    request.setAttribute("weekDay", DateUtil.getWeekDayString(new Date()));
    request.setAttribute("date", DateUtil.getDateString(new Date()));
    return "index";
}

From source file:net.testdriven.psiprobe.controllers.DecoratorController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    try {/*from   w  ww  .  ja v a 2  s .co m*/
        request.setAttribute("hostname", InetAddress.getLocalHost().getHostName());
    } catch (UnknownHostException e) {
        request.setAttribute("hostname", "unknown");
    }

    Properties version = (Properties) getApplicationContext().getBean("version");
    request.setAttribute("version", version.getProperty("probe.version"));

    Object uptimeStart = getServletContext().getAttribute(UptimeListener.START_TIME_KEY);
    if (uptimeStart != null && uptimeStart instanceof Long) {
        long l = (Long) uptimeStart;
        long uptime = System.currentTimeMillis() - l;
        long uptime_days = uptime / (1000 * 60 * 60 * 24);

        uptime = uptime % (1000 * 60 * 60 * 24);
        long uptime_hours = uptime / (1000 * 60 * 60);

        uptime = uptime % (1000 * 60 * 60);
        long uptime_mins = uptime / (1000 * 60);

        request.setAttribute("uptime_days", uptime_days);
        request.setAttribute("uptime_hours", uptime_hours);
        request.setAttribute("uptime_mins", uptime_mins);
    }

    //
    // Work out the language of the interface by matching resource files that we have
    // to the request locale.
    //
    List fileNames = getMessageFileNamesForLocale(request.getLocale());
    String lang = "en";
    for (Object fileName : fileNames) {
        String f = (String) fileName;
        if (getServletContext().getResource(f + ".properties") != null) {
            lang = f.substring(messagesBasename.length() + 1);
            break;
        }
    }

    request.setAttribute("lang", lang);

    return super.handleRequestInternal(request, response);
}

From source file:com.redhat.rhn.frontend.action.systems.CrashNoteEditAction.java

protected void setupPageAndFormValues(HttpServletRequest request, DynaActionForm daForm, Crash crash,
        CrashNote crNoteIn) {/*from w  w  w.  j  a  va 2  s .  com*/

    request.setAttribute(CRASH_ID, crash.getId());
    request.setAttribute(CRASH, crash);
    request.setAttribute(SID, crash.getServer().getId());

    if (crNoteIn != null) {
        daForm.set("subject", crNoteIn.getSubject());
        daForm.set("note", crNoteIn.getNote());
        request.setAttribute(CRASH_NOTE_ID, crNoteIn.getId());
    }
}

From source file:com.googlecode.psiprobe.controllers.DecoratorController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    try {//from  w  ww .  j a  v  a 2  s .  c o  m
        request.setAttribute("hostname", InetAddress.getLocalHost().getHostName());
    } catch (UnknownHostException e) {
        request.setAttribute("hostname", "unknown");
    }

    Properties version = (Properties) getApplicationContext().getBean("version");
    request.setAttribute("version", version.getProperty("probe.version"));

    Object uptimeStart = getServletContext().getAttribute(UptimeListener.START_TIME_KEY);
    if (uptimeStart != null && uptimeStart instanceof Long) {
        long l = ((Long) uptimeStart).longValue();
        long uptime = System.currentTimeMillis() - l;
        long uptime_days = uptime / (1000 * 60 * 60 * 24);

        uptime = uptime % (1000 * 60 * 60 * 24);
        long uptime_hours = uptime / (1000 * 60 * 60);

        uptime = uptime % (1000 * 60 * 60);
        long uptime_mins = uptime / (1000 * 60);

        request.setAttribute("uptime_days", new Long(uptime_days));
        request.setAttribute("uptime_hours", new Long(uptime_hours));
        request.setAttribute("uptime_mins", new Long(uptime_mins));
    }

    //
    // Work out the language of the interface by matching resource files that we have
    // to the request locale.
    //
    List fileNames = getMessageFileNamesForLocale(request.getLocale());
    String lang = "en";
    for (Iterator it = fileNames.iterator(); it.hasNext();) {
        String f = (String) it.next();
        if (getServletContext().getResource(f + ".properties") != null) {
            lang = f.substring(messagesBasename.length() + 1);
            break;
        }
    }

    request.setAttribute("lang", lang);

    return super.handleRequestInternal(request, response);
}

From source file:cn.vlabs.umt.ui.actions.FindPasswordAction.java

public ActionForward stepTwo(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    request.setAttribute("isStatic", "true");
    String uidStr = SessionUtils.getSessionVar(request, "findPswUserId");
    if (CommonUtils.isNull(uidStr)) {
        return stepOne(mapping, form, request, response);
    }/*from w  ww. ja  va 2 s  .co  m*/
    int uid = Integer.valueOf(uidStr);
    User user = getUserService().getUserByUid(uid);
    if (user == null || (CommonUtils.isNull(user.getSecurityEmail())
            && CommonUtils.isNull(user.getSecondaryEmails()) && user.isCoreMailOrUc())) {
        request.setAttribute("coreMailOnly", true);
    } else {
        String tempSecurityEmail = getUserService().getTempSecurityEmail(user.getId());
        if (CommonUtils.isNull(user.getSecurityEmail())) {
            user.setSecurityEmail(tempSecurityEmail);
        }
        request.setAttribute("coreMailOnly", false);
    }
    request.setAttribute("findPswUser", user);
    request.setAttribute("active", request.getParameter("active"));
    return mapping.findForward("find.password.stepTwo");
}

From source file:cn.vlabs.umt.ui.actions.FindPasswordAction.java

/**
 * ???//from  ww  w  .ja v  a  2 s  . c  om
 * 
 * */
public ActionForward sendRemindeEmail(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    request.setAttribute("isStatic", "true");
    String loginEmail = request.getParameter("loginEmail");
    int uid = Integer.valueOf(request.getParameter("uid"));
    if (loginEmail != null) {
        loginEmail = loginEmail.toLowerCase();
    }
    UserService us = getUserService();
    boolean flag;
    if (!ValidatorFactory.getValidCodeEqualsValidator(request).validate(request.getParameter("ValidCode"))) {
        flag = false;
    } else {
        us.sendChangeMail(new UMTContext(request).getLocale(), uid, loginEmail,
                ServiceFactory.getWebUrl(request));
        flag = true;
    }
    PrintWriter writer = response.getWriter();
    writer.println("{\"result\":" + flag + ",\"url\":\"" + EmailUrlTagUtils.getEmailLink(loginEmail) + "\"}");
    writer.flush();
    writer.close();
    return null;
}

From source file:com.netcracker.financeapp.controller.agent.AgentDeleteServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ArrayList<String> agentList = agentService.getAgentNames();
    request.setAttribute("agentList", agentList);

    request.setAttribute("clearAgent", "Select Agent");
    request.getRequestDispatcher("agent/agentDelete.jsp").forward(request, response);

}

From source file:net.incrementalism.tooter.SignUpServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (isBlank(request.getParameter("userName"))) {
        request.setAttribute("error", "'User Name' must not be empty.");
    } else if (isBlank(request.getParameter("email"))) {
        request.setAttribute("error", "'Email Address' must not be empty.");
    } else if (isBlank(request.getParameter("password"))) {
        request.setAttribute("error", "'Password' must not be empty.");
    } else if (isBlank(request.getParameter("passwordConfirm"))) {
        request.setAttribute("error", "'Confirm Password' must not be empty.");
    } else if (!request.getParameter("password").equals(request.getParameter("passwordConfirm"))) {
        request.setAttribute("error", "'Password' and 'Confirm Password' did not match.");
    } else {/*from   w w  w. ja  v  a 2s. c o m*/
        try {
            setCurrentUser(request, addUser(User.builder().userName(request.getParameter("userName"))
                    .email(request.getParameter("email")).password(request.getParameter("password")).build()));
            response.sendRedirect("/profile");
            return;
        } catch (DuplicateUserException e) {
            request.setAttribute("error", "User Name '" + e.getUserName() + "' is already taken.");
        }
    }
    request.getRequestDispatcher("/index.jsp").include(request, response);
}

From source file:com.bitranger.parknshop.buyer.controller.ShowItemDetail.java

@RequestMapping(value = "/item/{psItemId}", method = RequestMethod.GET)
public String showItmeDetail(@PathVariable Integer psItemId, HttpServletRequest req) {
    PsItem psItem = psItemDao.findById(psItemId);
    if (psItem == null)
        Utility.error("No such item");
    req.setAttribute("psItem", psItem);
    FetchOption option = new FetchOption();
    option.limit = 500;//ww  w.  ja  v a2 s. c  om
    option.offset = 0;
    option.sortOption = SortOption.DESCENDING;
    List<PsComment> psComments = psCommentDao.findByItemId(psItemId, option);
    req.setAttribute("psComments", psComments);
    return "detail";
}