Example usage for javax.servlet ServletRequest getParameter

List of usage examples for javax.servlet ServletRequest getParameter

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getParameter.

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:com.gamewin.weixin.web.task.ActivationCodeController.java

@RequiresRoles(value = { "admin", "TwoAdmin", "ThreeAdmin" }, logical = Logical.OR)
@RequestMapping(value = "create", method = RequestMethod.POST)
public String create(@Valid ActivationCode newActivationCode, RedirectAttributes redirectAttributes,
        ServletRequest request) {
    User user = new User(getCurrentUserId());
    String activationCodeCount = request.getParameter("activationCodeCount");
    if (!StringUtils.isEmpty(activationCodeCount)) {
        Integer activationCodeCountInt = Integer.parseInt(activationCodeCount);
        if (activationCodeCountInt > 0) {
            for (int i = 0; i < activationCodeCountInt; i++) {
                ActivationCode newActCode = new ActivationCode();
                newActCode.setActivationCode(UUID.randomUUID().toString().replaceAll("-", ""));
                newActCode.setActivationCodeType(newActivationCode.getActivationCodeType());
                newActCode.setCreateDate(new Date());
                newActCode.setTitle(newActivationCode.getTitle());
                newActCode.setDescription(newActivationCode.getDescription());
                newActCode.setUser(user);
                newActCode.setIsdelete(0);
                newActCode.setStatus("N");
                activationCodeService.saveActivationCode(newActCode);
            }// ww  w.  ja  v  a2 s  .  c  o  m
        }
    }

    redirectAttributes.addFlashAttribute("message", "??");
    return "redirect:/activationCode/";
}

From source file:pl.com.softproject.altkom.hibernate.forms.web.controller.FormControler.java

@RequestMapping(value = "/saveFormDate", method = RequestMethod.POST)
public String saveFormDate(ServletRequest request, @RequestParam("form_id") long formId) {

    Person person = new Person();

    person.setName(request.getParameter("person.name"));
    person.setAddress(new Address(request.getParameter("person.address.citi"),
            request.getParameter("person.address.street"), request.getParameter("person.address.postcode")));

    personDAO.save(person);//from   ww  w .  j a v  a  2  s  .  c om
    Form form = formDAO.findOne(formId);

    FormData formData = new FormData();
    formData.setForm(form);
    formData.setCreationDate(new Date());
    formData.setPerson(person);

    Enumeration<String> params = request.getParameterNames();

    while (params.hasMoreElements()) {
        String param = params.nextElement();

        if (logger.isDebugEnabled())
            logger.debug(param);

        if (param.startsWith("field_")) {
            long fieldId = Long.parseLong(param.replaceFirst("field_", ""));

            FormFieldValue value = new FormFieldValue();
            value.setFieldValue(request.getParameter(param));
            value.setFormData(formData);
            value.setFormField(new FormField(fieldId));
            formData.getAnswers().add(value);
        }
    }

    formDataDAO.save(formData);

    return "redirect:/showForms.htm";
}

From source file:org.yestech.lib.io.FileSystemFileDownloadFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String fileName = request.getParameter("file");
    FileInputStream inputStream = null;
    ServletOutputStream outputStream = response.getOutputStream();
    if (StringUtils.isNotBlank(fileName)) {
        try {//  ww w .  j  a  v  a2s  . co m

            File downloadFile = new File(baseDirectory, fileName);
            response.setContentLength((int) downloadFile.length());
            inputStream = openInputStream(downloadFile);
            copy(inputStream, outputStream);
            outputStream.flush();
            if (deleteAfterDownload) {
                downloadFile.delete();
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new RuntimeException(e);
        } finally {
            closeQuietly(inputStream);
            closeQuietly(outputStream);
        }

    }
}

From source file:com.gamewin.weixin.web.account.UserAdminController.java

@RequiresRoles("admin")
@RequestMapping(value = "update", method = RequestMethod.POST)
public String update(@Valid @ModelAttribute("user") User user, RedirectAttributes redirectAttributes,
        ServletRequest request) {
    String upuserId = request.getParameter("upuserId");
    if (!StringUtils.isEmpty(upuserId)) {
        User upuser = accountService.getUser(Long.parseLong(upuserId));
        if (upuser != null
                && ("TwoAdmin".equals(upuser.getRoles()) || "ThreeAdmin".equals(upuser.getRoles()))) {
            user.setUpuser(upuser);//from w  w w . j a  v a  2 s  .c o m
        }
    }
    accountService.updateUser(user);
    redirectAttributes.addFlashAttribute("message", "" + user.getLoginName() + "?");
    return "redirect:/admin/user";
}

From source file:org.pentaho.platform.web.http.security.PreAuthenticatedFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    try {/*from   w w w.ja va  2  s . c  om*/
        String assoKey = servletRequest.getParameter(ASSO_KEY);
        if (StringUtils.isEmpty(assoKey)) {
            return;
        }
        preAuthHolder.restoreSession(assoKey);

    } catch (Exception e) {
        log.error(e);
        // ensure that no credentials remain.
        SecurityContextHolder.getContext().setAuthentication(null);
        PentahoSessionHolder.removeSession();
    } finally {
        filterChain.doFilter(servletRequest, servletResponse);
    }
}

From source file:org.glassmaker.spring.oauth.OAuth2AuthenticationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (request.getParameter("code") != null) {
        AuthorizationCodeFlow flow = oAuth2Util.newAuthorizationCodeFlow();
        TokenResponse tokenResponse = oAuth2Util.newTokenRequest(flow, request.getParameter("code")).execute();

        // Extract the Google User ID from the ID token in the auth
        // response
        //String userId = ((GoogleTokenResponse) tokenResponse).parseIdToken().getPayload().getUserId();
        String subject = ((GoogleTokenResponse) tokenResponse).parseIdToken().getPayload().getSubject();
        //String email = (String) ((GoogleTokenResponse) tokenResponse).parseIdToken().getPayload().get("email");

        logger.info("Code exchange worked. User " + subject + " logged in.");
        flow.createAndStoreCredential(tokenResponse, subject);

        Authentication auth = new UsernamePasswordAuthenticationToken(subject, tokenResponse.getAccessToken(),
                (Collection<? extends GrantedAuthority>) new ArrayList<GrantedAuthority>());
        authManager.authenticate(auth);/*  w ww. j ava2s  . c  o  m*/
        SecurityContextHolder.getContext().setAuthentication(authManager.authenticate(auth));
        ((HttpServletRequest) request).getSession().setAttribute(
                HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
                SecurityContextHolder.getContext());

        if (auth != null) {
            onAuthenticationSuccess((HttpServletRequest) request, (HttpServletResponse) response, auth);
        }

    }
    chain.doFilter(request, response);

}

From source file:org.sakaiproject.metaobj.shared.mgt.impl.PortalParamManagerImpl.java

public Map getParams(ServletRequest request) {
    Map map = new Hashtable();

    for (Iterator i = getParameters().iterator(); i.hasNext();) {
        String key = (String) i.next();
        String value = request.getParameter(key);
        if (value == null) {
            value = (String) request.getAttribute(key);
        }/*from  w ww  .j  a  v  a 2 s.  co  m*/

        if (value != null) {
            map.put(key, value);
        }
    }

    return map;
}

From source file:com.agiletec.plugins.jpblog.aps.tags.util.BlogPagerTagHelper.java

private int getItemNumber(String truePagerId, ServletRequest request) {
    String stringItem = null;/*  www. j  av  a 2  s.  c  om*/
    if (null != truePagerId) {
        stringItem = request.getParameter(truePagerId + "_item");
    } else {
        stringItem = request.getParameter("item");
    }
    int item = 0;
    if (stringItem != null) {
        try {
            item = Integer.parseInt(stringItem);
        } catch (NumberFormatException e) {
            _logger.error("Error while parsing the stringItem {}", stringItem);
        }
    }
    return item;
}

From source file:com.feilong.taglib.display.barcode.BarcodeServlet.java

@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException {
    // ? ? ? barcodeId
    String barcodeId = request.getParameter(BarcodeRequestParams.BARCODE_ID);
    Validate.notEmpty(barcodeId, "barcodeId can't be null/empty!");

    //  barcodeId ?session?? BarcodeContentsAndConfig
    KeyAccessor keyAccessor = new SessionKeyAccessor();

    BarcodeContentsAndConfig barcodeContentsAndConfig = keyAccessor.get(barcodeId,
            (HttpServletRequest) request);
    Validate.notNull(barcodeContentsAndConfig, "barcodeContentsAndConfig can't be null!");

    // render//from   ww w  .  ja  va2 s . c  o m
    render(barcodeContentsAndConfig, response);
}

From source file:com.eu.evaluation.web.controller.EvaluateItemController.java

/**
 * //from   w  w w  .j  a  v a2  s  .  c o  m
 * @param evaluateType 
 * @param objectDictionaryID ID
 * @param fieldDictionaryID ID
 * @param request 
 * @return 
 */
@ResponseBody
@RequestMapping(value = "/evaluateItem", method = RequestMethod.POST, consumes = { "application/json" })
public EvaluateItem saveEvaluateItem(@RequestParam("evaluateType") EvaluateTypeEnum evaluateType,
        @RequestParam("objectDictionaryID") String objectDictionaryID,
        @RequestParam("fieldDictionaryID") String fieldDictionaryID, ServletRequest request) {

    Map<String, Object> otherMap = new HashMap<String, Object>();
    for (Object key : request.getParameterMap().keySet()) {
        otherMap.put((String) key, request.getParameter((String) key));
    }

    return evaluateTemplateService.createOrReplaceEvaluateItem(EvaluateTypeEnum.NOT_NULL, objectDictionaryID,
            fieldDictionaryID, otherMap);
}