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:net.sourceforge.fenixedu.presentationTier.Action.credits.ShowAllTeacherCreditsResumeAction.java

protected void readAllTeacherCredits(HttpServletRequest request, Teacher teacher) throws FenixActionException {

    request.setAttribute("teacher", teacher);
    Department department = teacher.getCurrentWorkingDepartment();
    if (department != null) {
        request.setAttribute("department", department.getRealName());
    }//  w w  w .j  ava2s. c  o m

    List<CreditLineDTO> creditsLines;
    try {
        creditsLines = ReadAllTeacherCredits.run(teacher.getExternalId());
    } catch (ParseException e) {
        throw new FenixActionException(e);
    }

    request.setAttribute("creditsLinesSize", creditsLines.size());

    BeanComparator dateComparator = new BeanComparator("executionPeriod.beginDate");
    Iterator orderedCreditsLines = new OrderedIterator(creditsLines.iterator(), dateComparator);

    request.setAttribute("creditsLines", orderedCreditsLines);
}

From source file:pl.edu.icm.comac.vis.server.TimingInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    request.setAttribute(HANDLING_START_ATT, System.currentTimeMillis());
    return true;/*w w w. j a v  a2  s . c  o  m*/
}

From source file:nl.surfnet.coin.selfservice.interceptor.FeatureInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    request.setAttribute("developmentMode", developmentMode); // for use on error page
    return true;// w  ww . j a v  a  2 s . c o  m
}

From source file:com.ibm.jaggr.core.test.TestUtils.java

public static HttpServletRequest createMockRequest(IAggregator aggregator,
        final Map<String, Object> requestAttributes, final Map<String, String[]> requestParameters,
        final Cookie[] cookies, final Map<String, String> headers) {
    HttpServletRequest mockRequest = EasyMock.createNiceMock(HttpServletRequest.class);
    if (requestAttributes != null) {
        requestAttributes.put(IAggregator.AGGREGATOR_REQATTRNAME, aggregator);
        EasyMock.expect(mockRequest.getAttribute((String) EasyMock.anyObject()))
                .andAnswer(new IAnswer<Object>() {
                    public Object answer() throws Throwable {
                        return requestAttributes.get((String) EasyMock.getCurrentArguments()[0]);
                    }// w w w.  ja  va  2  s .  c om
                }).anyTimes();
        mockRequest.setAttribute((String) EasyMock.anyObject(), EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                String name = (String) EasyMock.getCurrentArguments()[0];
                Object value = EasyMock.getCurrentArguments()[1];
                requestAttributes.put(name, value);
                return null;
            }
        }).anyTimes();
        mockRequest.removeAttribute((String) EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                String name = (String) EasyMock.getCurrentArguments()[0];
                requestAttributes.remove(name);
                return null;
            }
        }).anyTimes();
    } else {
        EasyMock.expect(mockRequest.getAttribute(IAggregator.AGGREGATOR_REQATTRNAME)).andReturn(aggregator)
                .anyTimes();
    }
    if (requestParameters != null) {
        EasyMock.expect(mockRequest.getParameter((String) EasyMock.anyObject()))
                .andAnswer(new IAnswer<String>() {
                    public String answer() throws Throwable {
                        String[] ary = requestParameters.get((String) EasyMock.getCurrentArguments()[0]);
                        return ary != null && ary.length > 0 ? ary[0] : null;
                    }
                }).anyTimes();
        EasyMock.expect(mockRequest.getParameterMap()).andAnswer(new IAnswer<Map<String, String[]>>() {
            @Override
            public Map<String, String[]> answer() throws Throwable {
                return requestParameters;
            }
        }).anyTimes();
    }
    if (cookies != null) {
        EasyMock.expect(mockRequest.getCookies()).andAnswer(new IAnswer<Cookie[]>() {
            public Cookie[] answer() throws Throwable {
                return cookies;
            }
        }).anyTimes();
    }
    if (headers != null) {
        EasyMock.expect(mockRequest.getHeader((String) EasyMock.anyObject())).andAnswer(new IAnswer<String>() {
            public String answer() throws Throwable {
                return headers.get((String) EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();
    }
    return mockRequest;
}

From source file:org.ucll.ip.spring_ip_project.controller.TankController.java

@RequestMapping(method = { RequestMethod.POST }, value = "/overview")
public ModelAndView getTanks(HttpServletRequest req) {
    String name = req.getParameter("player");
    req.setAttribute("player", name);
    ModelAndView view = new ModelAndView("tanks", "tanks", system.getTanksOfPlayer(name));
    view.addObject("games", system.getTotalGamesPlayed(name));
    return view;/*from ww  w.  ja v  a  2 s. c  o  m*/
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.candidacy.erasmus.ErasmusIndividualCandidacyProcessDA.java

public ActionForward executeSetCoordinatorValidationInvalid(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response) {
    request.setAttribute(getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
    return mapping.findForward("set-coordinator-validation");
}

From source file:dijalmasilva.controllers.User.java

@RequestMapping("/new")
public String novoUsuario(Usuario u, HttpServletRequest req) {
    Usuario usuario = service.salvar(u);
    if (usuario != null) {
        req.setAttribute("result", "Usurio cadastrado com sucesso.");
    } else {/*  w ww .  j  av  a2 s . c  o m*/
        req.setAttribute("result", "No foi possvel cadastrar o usurio \n Username j est em uso.");
    }
    return "home";
}

From source file:org.sakaiproject.metaobj.shared.control.ForwardView.java

/**
 * Subclasses must implement this method to render the view.
 * <p>The first take will be preparing the request: This may include setting
 * the model elements as request attributes, e.g. in the case of a JSP view.
 *
 * @param model    combined output Map, with dynamic values taking precedence
 *                 over static attributes
 * @param request  current HTTP request/*from  w w  w .  j  ava2  s  .c  o m*/
 * @param response current HTTP response
 * @throws Exception if rendering failed
 */
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    request.setAttribute("action", getUrl());

    for (Iterator i = model.entrySet().iterator(); i.hasNext();) {
        Map.Entry entry = (Map.Entry) i.next();
        request.setAttribute((String) entry.getKey(), entry.getValue());
    }

    request.getRequestDispatcher(getUrl()).forward(request, response);
}

From source file:org.tangram.spring.MeasureTimeInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    request.setAttribute("start.time", System.currentTimeMillis());
    return super.preHandle(request, response, handler);
}

From source file:info.magnolia.cms.filters.CosMultipartRequestFilter.java

/**
 * Adds all request paramaters as request attributes.
 * @param request HttpServletRequest//ww  w.j a va2 s.  c om
 */
private static MultipartForm parseParameters(HttpServletRequest request) throws IOException {
    MultipartForm form = new MultipartForm();
    String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8");
    MultipartRequest multi = new MultipartRequest(request, Path.getTempDirectoryPath(), MAX_FILE_SIZE, encoding,
            null);
    Enumeration params = multi.getParameterNames();
    while (params.hasMoreElements()) {
        String name = (String) params.nextElement();
        String value = multi.getParameter(name);
        form.addParameter(name, value);
        String[] s = multi.getParameterValues(name);
        if (s != null) {
            form.addparameterValues(name, s);
        }
    }
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements()) {
        String name = (String) files.nextElement();
        form.addDocument(name, multi.getFilesystemName(name), multi.getContentType(name), multi.getFile(name));
    }
    request.setAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME, form);
    return form;
}