Java Code Examples for javax.servlet.http.HttpServletRequest#setAttribute()

The following examples show how to use javax.servlet.http.HttpServletRequest#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrgDetailsAction.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
private void setupFormValues(HttpServletRequest request,
        DynaActionForm daForm,
        Long oid,
        Org org) {

    OrgDto dto = OrgManager.toDetailsDto(org);
    daForm.set("submitted", Boolean.TRUE);
    daForm.set("orgName", dto.getName());
    daForm.set("id", dto.getId().toString());
    daForm.set("users", dto.getUsers().toString());
    daForm.set("systems", dto.getSystems().toString());
    daForm.set("actkeys", dto.getActivationKeys().toString());
    daForm.set("ksprofiles", dto.getKickstartProfiles().toString());
    daForm.set("groups", dto.getServerGroups().toString());
    daForm.set("cfgchannels", dto.getConfigChannels().toString());

    request.setAttribute("org", org);
    request.setAttribute(RequestContext.ORG_ID, oid);
}
 
Example 2
Source File: PublicInstitutionPhdProgramsCandidacyProcessDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ActionForward editPersonalData(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {

    final PhdProgramCandidacyProcessBean bean = getCandidacyBean();
    PhdProgramCandidacyProcess process = getProcess(request);

    canEditCandidacy(request, process.getCandidacyHashCode());
    canEditPersonalInformation(request, process.getPerson());

    try {
        ExecuteProcessActivity
                .run(process.getIndividualProgramProcess(), EditPersonalInformation.class, bean.getPersonBean());
    } catch (final DomainException e) {
        addErrorMessage(request, e.getKey(), e.getArgs());
        request.setAttribute("candidacyBean", bean);
        return mapping.findForward("editPersonalData");
    }

    return viewCandidacy(mapping, form, request, response, process.getCandidacyHashCode());
}
 
Example 3
Source File: CashController.java    From aaden-pay with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/form", method = RequestMethod.GET)
public String getHelp(Model model, HttpServletRequest request) {

	// 从数据库获取一个已绑定的银行卡
	ThirdBankSend bankSend = new ThirdBankSend();
	bankSend.setBankVerifyType(BankVerifyType.CONFIRM);
	bankSend.setIsValid(IsValid.VALID.getValue());
	List<ThirdBankSend> list = dbBankService.getPage(bankSend, "1", "1").getResult();

	ThirdBankSend bank = null;
	if (!CollectionUtils.isEmpty(list)) {
		bank = list.get(0);
		request.getSession().setAttribute(BANK_KEY, bank);
	}

	// 省份列表
	List<Area> provs = bankService.getAreaLabel("000000");
	request.setAttribute("bank", bank);
	request.setAttribute("provs", provs);

	return "form/cash_form";
}
 
Example 4
Source File: CacheSessionProvider.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
public String getSessionId(HttpServletRequest request,
		HttpServletResponse response) {
	String root = (String) request.getAttribute(CURRENT_SESSION_ID);
	if (root != null) {
		return root;
	}
	root = RequestUtils.getRequestedSessionId(request);
	if (root == null || root.length() != 32 || !sessionCache.exist(root)) {
		do {
			root = sessionIdGenerator.get();
		} while (sessionCache.exist(root));
		sessionCache.setSession(root, new HashMap<String, Serializable>(),
				sessionTimeout);
		response.addCookie(createCookie(request, root));
	}
	request.setAttribute(CURRENT_SESSION_ID, root);
	return root;
}
 
Example 5
Source File: QueryTestAction.java    From ralasafe with MIT License 6 votes vote down vote up
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
		throws ServletException, IOException {
	String oper=req.getParameter( "oper" );		
	QueryTestHandler handler=getHandler( req );
	req.setAttribute( "handler", handler );
	
	if( log.isDebugEnabled() ) {
		log.debug( "oper=" + oper + ", query="+handler.getQuery().getName() );
	}
	
	if( "return".equals( oper ) ) {
		String gotoPage=handler.getManagePage();
		
		// remove handler from session
		req.getSession().removeAttribute( getHandlerAttributeKey( req ) );
		
		// goto manage page
		resp.sendRedirect( gotoPage );
		return;
	} else {
		WebUtil.forward( req, resp, "/ralasafe/query/test.jsp" );
	}
}
 
Example 6
Source File: ProjectSubmissionDispatchAction.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EntryPoint
public ActionForward viewProjectsWithOnlineSubmission(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws FenixActionException, FenixServiceException {

    Student student = getUserView(request).getPerson().getStudent();
    ManageStudentStatuteBean bean = getRenderedObject("studentBean");
    if (bean == null) {
        bean = new ManageStudentStatuteBean(student);
    }

    request.setAttribute("studentBean", bean);
    request.setAttribute("attends", student.getAttendsForExecutionPeriod(bean.getExecutionPeriod()));

    return mapping.findForward("viewProjectsWithOnlineSubmission");

}
 
Example 7
Source File: ErasmusCandidacyProcessDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setChooseDegreeBean(HttpServletRequest request) {
    ChooseDegreeBean chooseDegreeBean = (ChooseDegreeBean) getObjectFromViewState("choose.degree.bean");
    if (chooseDegreeBean == null) {
        chooseDegreeBean = new ChooseDegreeBean(getProcess(request));
        String degreeEid = request.getParameter("degreeEid");
        if (degreeEid != null && !degreeEid.isEmpty()) {
            Degree degree = FenixFramework.getDomainObject(degreeEid);
            chooseDegreeBean.setDegree(degree);
        }
    }
    request.setAttribute("chooseDegreeBean", chooseDegreeBean);
}
 
Example 8
Source File: ArticleController.java    From Jantent with MIT License 5 votes vote down vote up
/**
 * 文章发表页面
 *
 * @param request
 * @return
 */
@GetMapping(value = "/publish")
public String newArticle(HttpServletRequest request) {
    List<MetaVo> categories = metaService.getMetas(Types.CATEGORY.getType());
    request.setAttribute("categories", categories);
    request.setAttribute(Types.ATTACH_URL.getType(), Commons.site_option(Types.ATTACH_URL.getType()));
    return "admin/article_edit";
}
 
Example 9
Source File: AbstractHTTPServlet.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void redirect(HttpServletRequest request, HttpServletResponse response, String pathInfo)
    throws ServletException {
    boolean customServletPath = dispatcherServletPath != null;
    String theServletPath = customServletPath ? dispatcherServletPath : "/";

    ServletContext sc = super.getServletContext();
    RequestDispatcher rd = dispatcherServletName != null
        ? sc.getNamedDispatcher(dispatcherServletName)
        : sc.getRequestDispatcher((theServletPath + pathInfo).replace("//", "/"));
    if (rd == null) {
        String errorMessage = "No RequestDispatcher can be created for path " + pathInfo;
        if (dispatcherServletName != null) {
            errorMessage += ", dispatcher name: " + dispatcherServletName;
        }
        throw new ServletException(errorMessage);
    }
    try {
        for (Map.Entry<String, String> entry : redirectAttributes.entrySet()) {
            request.setAttribute(entry.getKey(), entry.getValue());
        }
        HttpServletRequest servletRequest =
            new HttpServletRequestRedirectFilter(request, pathInfo, theServletPath, customServletPath);
        if (PropertyUtils.isTrue(getServletConfig().getInitParameter(REDIRECT_WITH_INCLUDE_PARAMETER))) {
            rd.include(servletRequest, response);
        } else {
            rd.forward(servletRequest, response);
        }
    } catch (Throwable ex) {
        throw new ServletException("RequestDispatcher for path " + pathInfo + " has failed", ex);
    }
}
 
Example 10
Source File: HelpJsfTool.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @see org.sakaiproject.jsf.util.JsfTool#dispatch(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
protected void dispatch(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
{
   // if magic switch turned on, go to external webapp
   if (! "sakai".equals(EXTERNAL_WEBAPP_URL)) {
      String docId = req.getParameter("help");

      if (docId != null) {
       Pattern p = Pattern.compile(HELP_DOC_REGEXP);
       Matcher m = p.matcher(docId);
       
       if (!m.matches()) {
       	docId = "unknown";
       }
      }
      String extUrl = EXTERNAL_WEBAPP_URL;
      
      if (docId != null && !"".equals(docId)) {
   	   extUrl += "/tags?tag=" + docId; // format to use if EXTERNAL_WEBAPP_URL = associated ScreenSteps home
      }
   	
      res.sendRedirect(extUrl);
   return;
   }

  req.setAttribute(TOC_ATTRIBUTE, Web.returnUrl(req, TOC_PATH));
  req.setAttribute(SEARCH_ATTRIBUTE, Web.returnUrl(req, SEARCH_PATH));
  req.setAttribute(HELP_ATTRIBUTE, Web.returnUrl(req, HELP_PATH));
  super.dispatch(req, res);
}
 
Example 11
Source File: MarkSheetDispatchAction.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActionForward prepareConfirmMarkSheet(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) {
    DynaActionForm form = (DynaActionForm) actionForm;
    request.setAttribute("markSheet", getDomainObject(form, "msID"));

    return mapping.findForward("confirmMarkSheet");
}
 
Example 12
Source File: CreateBookServlet.java    From getting-started-java with Apache License 2.0 5 votes vote down vote up
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
    IOException {
  req.setAttribute("action", "Add");          // Part of the Header in form.jsp
  req.setAttribute("destination", "create");  // The urlPattern to invoke (this Servlet)
  req.setAttribute("page", "form");           // Tells base.jsp to include form.jsp
  req.getRequestDispatcher("/base.jsp").forward(req, resp);
}
 
Example 13
Source File: TeamController.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
@RequestMapping("manageTeam.htm")
public ModelAndView manageTeam(HttpServletRequest req, HttpServletResponse res) {
    String teamId = ServletRequestUtils.getStringParameter(req, "teamId", "");
    User user = (User) req.getSession().getAttribute("user");
    Team team = teamService.findById(Team.class, teamId);
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(UserTeam.class)
            .add(Restrictions.eq("team", team))
            .add(Restrictions.eq("userState", "批准"))
            .addOrder(Order.desc("approveDate"));
    List<UserTeam> userTeams = (List<UserTeam>) teamService.queryAllOfCondition(UserTeam.class, detachedCriteria);
    labels = labelService.getTenHotLabels();
    previousLabels = labelService.getObjectLabels(team.getTeamId(), "team");
    UserTeam userTeam = new UserTeam();
    UserTeam userTeam2 = new UserTeam();
    for (int i = 0; i < userTeams.size(); i++) {
        if (userTeams.get(i).getUser().getUserId().equals(user.getUserId())) {
            userTeam = userTeams.get(i);
        }
        if (userTeams.get(i).getUserPosition().equals("组长")) {
            userTeam2 = userTeams.get(i);
        }
    }
    int memberNum = userTeams.size();
    req.setAttribute("userTeams", userTeams);
    req.setAttribute("memberNum", memberNum);
    req.setAttribute("userTeam", userTeam);
    req.setAttribute("userTeam2", userTeam2);
    req.setAttribute("labels", labels);
    req.setAttribute("previousLabels", previousLabels);
    return new ModelAndView("/team/admin");
}
 
Example 14
Source File: ExecutionPeriodDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActionForward chooseStudentById(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    final Registration registration = getDomainObject(request, "registrationId");
    final ExecutionSemester executionSemester = getDomainObject(request, "executionSemesterId");

    request.setAttribute("registration", registration);
    return new ShowStudentTimeTable().forwardToShowTimeTable(registration, mapping, request, executionSemester);
}
 
Example 15
Source File: VelocityPortalRenderEngine.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void setupForward(HttpServletRequest req, HttpServletResponse res,
		Placement p, String skin)
{

	String headJs = (String) req.getAttribute("sakai.html.head.js");
	String headCssToolBase = (String) req.getAttribute("sakai.html.head.css.base");
	String headCssToolSkin = (String) req.getAttribute("sakai.html.head.css.skin");
	String bodyonload = (String) req.getAttribute("sakai.html.body.onload");
	String customUserCss = generateStyleAbleStyleSheet();
	if (customUserCss != null)
	{
		customUserCss = "<style type=\"text/css\" title=\"StyleAble\">\n"
				+ customUserCss + "</style>\n";
	}
	else
	{
		customUserCss = "";
	}
	String styleAbleJs = generateStyleAbleJavaScript();
	if (styleAbleJs != null)
	{
		styleAbleJs = "<script "
				+ "type=\"text/javascript\" language=\"JavaScript\">\n" + styleAbleJs
				+ "\n</script>\n";
		headJs = headJs + styleAbleJs;
		bodyonload = bodyonload + "styleableonload();";
	}
	headCssToolSkin = headCssToolSkin + customUserCss;
	String headCss = headCssToolBase + headCssToolSkin + customUserCss;
	String head = headCss + headJs;

	req.setAttribute("sakai.html.head", head);
	req.setAttribute("sakai.html.head.css", headCss);
	req.setAttribute("sakai.html.head.js", headJs);
	req.setAttribute("sakai.html.head.css.base", headCssToolBase);
	req.setAttribute("sakai.html.head.css.skin", headCssToolSkin);
	req.setAttribute("sakai.html.body.onload", bodyonload);

}
 
Example 16
Source File: BooksServlet.java    From java-course-ee with MIT License 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    if (request.getParameter("logout") != null) {
        request.getSession().invalidate();
        response.sendRedirect("/books");
        return;
    }

    request.setAttribute("books", BookStore.getBooks());
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/public/books.jsp");
    dispatcher.forward(request, response);

}
 
Example 17
Source File: DuplicateSystemsAction.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * {@inheritDoc}
 */
public ActionForward execute(ActionMapping mapping,
        ActionForm formIn,
        HttpServletRequest request,
        HttpServletResponse response) {

    RequestContext ctx = new RequestContext(request);
    request.setAttribute(mapping.getParameter(), mapping.getParameter());

    long inactiveHours = 24;
    if (request.getParameter(INACTIVE_COUNT) != null) {
        inactiveHours = Long.parseLong(request.getParameter(INACTIVE_COUNT));
    }
    request.setAttribute(INACTIVE_COUNT, inactiveHours);


    ListRhnSetHelper helper = new ListRhnSetHelper(this, request, getSetDecl());
    helper.setWillClearSet(false);
    helper.execute();
    if (helper.isDispatched()) {
        return mapping.findForward(RhnHelper.CONFIRM_FORWARD);
    }


    String inactiveButton = ListTagUtil.makeExtraButtonName(helper.getUniqueName());
    if (!StringUtils.isBlank(request.getParameter(inactiveButton))) {
        List<DuplicateSystemGrouping> list = getResult(ctx);

        RhnSet set = helper.getSet();
        for (DuplicateSystemGrouping grp : list) {
            for (NetworkDto dto : grp.getSystems()) {
                if (dto.getInactive() > 0) {
                    set.add(dto.getId().toString());
                }
            }
        }

        RhnSetManager.store(set);
        helper.resync(request);

    }



    request.setAttribute(inactiveButton,
            "system.select.inactive");
    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example 18
Source File: CompareSystemSetupAction.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public ActionForward execute(ActionMapping mapping,
                             ActionForm formIn,
                             HttpServletRequest request,
                             HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    processRequestAttributes(requestContext);

    Long sid = requestContext.getRequiredParam(RequestContext.SID);
    Long sid1 = requestContext.getRequiredParam(RequestContext.SID1);
    Set sessionSet = SessionSetHelper.lookupAndBind(request, getDecl(sid));

    //if its not submitted
    // ==> this is the first visit to this page
    // clear the 'dirty set'
    if (!requestContext.isSubmitted()) {
        sessionSet.clear();
    }

    SessionSetHelper helper = new SessionSetHelper(request);

    if (request.getParameter("dispatch") != null) {
        // if its one of the Dispatch actions handle it..
        helper.updateSet(sessionSet, LIST_NAME);
        if (!sessionSet.isEmpty()) {
            return handleDispatchAction(mapping, requestContext);
        }
        RhnHelper.handleEmptySelection(request);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(RequestContext.SID, sid.toString());
        params.put(RequestContext.SID1, sid1.toString());
        return getStrutsDelegate().forwardParams(
                mapping.findForward("error"), params);
    }
    DataResult dataSet = getDataResult(requestContext);
    // if its a list action update the set and the selections
    if (ListTagHelper.getListAction(LIST_NAME, request) != null) {
        helper.execute(sessionSet, LIST_NAME, dataSet);
    }

    // if I have a previous set selections populate data using it
    if (!sessionSet.isEmpty()) {
        helper.syncSelections(sessionSet, dataSet);
        ListTagHelper.setSelectedAmount(LIST_NAME, sessionSet.size(), request);
    }

    request.setAttribute(ListTagHelper.PARENT_URL,
            request.getRequestURI() + "?sid=" + sid + "&sid_1=" + sid1);

    request.setAttribute(RequestContext.PAGE_LIST, dataSet);

    ListTagHelper.bindSetDeclTo(LIST_NAME, getDecl(sid), request);
    TagHelper.bindElaboratorTo(LIST_NAME, dataSet.getElaborator(), request);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example 19
Source File: SecondCycleIndividualCandidacyProcessDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ActionForward executeEditCandidacyInformationInvalid(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response) {
    request.setAttribute(getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
    return mapping.findForward("edit-candidacy-information");
}
 
Example 20
Source File: LoginServlet.java    From MavenIn28Minutes with MIT License 4 votes vote down vote up
private void addGlobalLoginErrorAttribute(HttpServletRequest request) {
	request.setAttribute("error",
			resourceBundle.getString("login.form.incomplete.details"));
}