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:org.jsecurity.web.attr.AbstractWebAttribute.java

protected T getFromRequestParam(ServletRequest request) {
    T value = null;// w w w  . java2s  .c  om

    String paramName = getName();
    String paramValue = request.getParameter(paramName);
    if (paramValue != null) {
        if (log.isTraceEnabled()) {
            log.trace("Found string value [" + paramValue + "] from HttpServletRequest parameter [" + paramName
                    + "]");
        }
        value = fromStringValue(paramValue);
    } else {
        if (log.isTraceEnabled()) {
            log.trace("No string value found in the HttpServletRequest under parameter named [" + paramName
                    + "]");
        }
    }

    return value;
}

From source file:CheckFilter.java

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

    Enumeration params = request.getParameterNames();
    boolean rejected = false;

    while (params.hasMoreElements()) {

        if (isEmpty(request.getParameter((String) params.nextElement()))) {
            reject(request, response);//from www.  ja  v a  2 s . co m
            rejected = true;
        }

    }

    if (!rejected)
        chain.doFilter(request, response);

}

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

@Override
public IPagerVO getPagerVO(Collection collection, String pagerId, boolean pagerIdFromFrame, int max,
        boolean isAdvanced, int offset, ServletRequest request) throws ApsSystemException {
    IPagerVO pagerVo = null;/*from  w w  w  .j a  va 2s.  c  om*/
    try {
        String truePagerId = this.getPagerId(pagerId, pagerIdFromFrame, request);
        String contentId = request.getParameter("contentId");
        this.setContentId(contentId);
        int item = this.getItemNumber(truePagerId, request);
        int maxElement = this.getMaxElementForItem(max, request);
        if (this.isThereBlogContentIdParam(request, collection)) {
            item = this.getItemParamBlogContentIdParam(item, contentId, request, collection);
            maxElement = 1;
        }
        pagerVo = this.buildPageVO(collection, item, maxElement, truePagerId, isAdvanced, offset);
    } catch (Throwable t) {
        _logger.error("Error while preparing the pagerVo object", t);
        throw new ApsSystemException("Error while preparing the pagerVo object", t);
    }
    return pagerVo;
}

From source file:it.drwolf.ridire.filters.TmpResourcesFilter.java

@SuppressWarnings("unchecked")
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain arg2)
        throws IOException, ServletException {
    String filename = req.getParameter("filename");
    String encoding = req.getParameter("encoding");
    String tempDir = System.getProperty("java.io.tmpdir");
    String freqList = req.getParameter("freqList");
    String tsvList = req.getParameter("tsvList");
    if (filename != null && encoding != null && filename.indexOf(tempDir) != -1) {
        try {/*from   w ww  . jav  a  2s  . c  o  m*/
            Lifecycle.beginCall();
            if (resp instanceof HttpServletResponse) {
                HttpServletResponse response = (HttpServletResponse) resp;
                response.setContentType("text/html");
                response.setCharacterEncoding(encoding);
                response.setHeader("Expires", "0");
                response.setHeader("Date", new Date().toString());
                response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
                response.setHeader("Pragma", "public");
                File file = new File(filename);
                if (file.exists() && file.canRead()) {
                    String ret = FileUtils.readFileToString(file, encoding);
                    response.getWriter().write(ret);
                    response.getWriter().flush();
                    response.getWriter().close();
                }
                // FacesContext.getCurrentInstance().responseComplete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Lifecycle.endCall();
        }
    } else if (freqList != null && freqList.trim().length() > 0
            || tsvList != null && tsvList.trim().length() > 0) {
        try {
            Lifecycle.beginCall();
            String contentType = "application/vnd.oasis.opendocument.spreadsheet";
            File file = null;
            if (freqList != null) {
                file = new File(TmpResourcesFilter.LF_DIR + freqList + ".ods");
                if (freqList.equals("RIDIRE_LF")) {
                    file = new File(TmpResourcesFilter.LF_DIR + freqList + ".zip");
                    contentType = "application/zip";
                }
            } else {
                String zipFileName = tsvList.replaceAll("\\s\\(TSV\\)", "");
                file = new File(TmpResourcesFilter.LF_DIR + zipFileName + ".zip");
                contentType = "application/zip";
            }
            if (file.exists() && file.canRead()) {
                if (resp instanceof HttpServletResponse) {
                    HttpServletResponse response = (HttpServletResponse) resp;
                    response.setContentType(contentType);
                    response.setHeader("Expires", "0");
                    if (freqList != null) {
                        if (freqList.equals("RIDIRE_LF")) {
                            response.addHeader("Content-disposition",
                                    "attachment; filename=\"" + freqList + ".zip\"");
                        } else {
                            response.addHeader("Content-disposition",
                                    "attachment; filename=\"" + freqList + ".ods\"");
                        }
                    } else if (tsvList != null) {
                        response.addHeader("Content-disposition",
                                "attachment; filename=\"" + tsvList + ".zip\"");
                    }
                    response.setHeader("Date", new Date().toString());
                    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
                    response.setHeader("Pragma", "public");
                    byte[] lf = FileUtils.readFileToByteArray(file);
                    response.getOutputStream().write(lf);
                    response.getOutputStream().flush();
                    response.getOutputStream().close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Lifecycle.endCall();
        }
    } else {
        Map<String, String[]> pMap = req.getParameterMap();
        final Map<String, String[]> additionalParams = new HashMap<String, String[]>();
        for (String key : pMap.keySet()) {
            // if (key.equals("forma") || key.equals("lemma")
            // || key.equals("pos") || key.equals("phrase")
            // || key.startsWith("pattern")) {
            String[] values = pMap.get(key);
            if (values != null && values.length == 1) {
                byte[] bytes = values[0].getBytes("ISO-8859-1");
                additionalParams.put(key, new String[] { new String(bytes, "UTF-8") });
            }
            // }
        }
        HttpServletRequest httpServletRequest = new PrettyFacesWrappedRequest((HttpServletRequest) req,
                additionalParams);
        arg2.doFilter(httpServletRequest, resp);
    }
}

From source file:gov.nih.nci.cabig.caaers.web.study.SolicitedAdverseEventTab.java

/**
 * Returns the value associated with the <code>attributeName</code>, if present in
 * HttpRequest parameter, if not available, will check in HttpRequest attribute map.
 *//*from   ww w. java  2s  . c o m*/
protected Object findInRequest(final ServletRequest request, final String attributName) {
    Object attr = request.getParameter(attributName);
    if (attr == null) {
        attr = request.getAttribute(attributName);
    }
    return attr;
}

From source file:edu.umich.ctools.sectionsUtilityTool.SectionUtilityToolFilter.java

public void setLaunchType(ServletRequest request, HttpSession session) {
    if (BASIC_LTI_LAUNCH_REQUEST.equals(request.getParameter(LTI_MESSAGE_TYPE))
            && session.getAttribute(LAUNCH_TYPE) == null) {
        session.setAttribute(LAUNCH_TYPE, "lti");
    }/* ww  w  .jav a 2s  . co m*/
    if (session.getAttribute(LAUNCH_TYPE) == null) {
        session.setAttribute(LAUNCH_TYPE, "sc");
    }
}

From source file:dk.netarkivet.harvester.webinterface.SnapshotHarvestDefinition.java

/**
 * Extracts all required parameters from the request, checks for any inconsistencies, and passes the requisite data
 * to the updateHarvestDefinition method for processing. If the "update" parameter is not set, this method does
 * nothing.//from ww  w  .  java2  s.  c o  m
 * <p>
 * The parameters in the request are defined in Definitions-edit-snapshot-harvest.jsp.
 *
 * @param context The context of the web request.
 * @param i18n Translation information
 * @throws ForwardedToErrorPage if an error happened that caused a forward to the standard error page, in which case
 * further JSP processing should be aborted.
 */
public void processRequest(PageContext context, I18n i18n) {
    ArgumentNotValid.checkNotNull(context, "PageContext context");
    ArgumentNotValid.checkNotNull(i18n, "I18n i18n");

    ServletRequest request = context.getRequest();
    if (request.getParameter(Constants.UPDATE_PARAM) == null) {
        return;
    }

    HTMLUtils.forwardOnEmptyParameter(context, Constants.HARVEST_PARAM);

    String name = request.getParameter(Constants.HARVEST_PARAM);
    String comments = request.getParameter(Constants.COMMENTS_PARAM);

    long objectLimit = HTMLUtils.parseOptionalLong(context, Constants.DOMAIN_OBJECTLIMIT_PARAM,
            dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_OBJECTS);
    long byteLimit = HTMLUtils.parseOptionalLong(context, Constants.DOMAIN_BYTELIMIT_PARAM,
            dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_BYTES);
    long runningtimeLimit = HTMLUtils.parseOptionalLong(context, Constants.JOB_TIMELIMIT_PARAM,
            dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_JOB_RUNNING_TIME);

    Long oldHarvestId = HTMLUtils.parseOptionalLong(context, Constants.OLDSNAPSHOT_PARAM, null);

    if (oldHarvestId != null && !hdDaoProvider.get().exists(oldHarvestId)) {
        HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvestdefinition.0.does.not.exist",
                oldHarvestId);
        throw new ForwardedToErrorPage("Old harvestdefinition " + oldHarvestId + " does not exist");
    }

    FullHarvest hd;
    if ((request.getParameter(Constants.CREATENEW_PARAM) != null)) {
        if (hdDaoProvider.get().getHarvestDefinition(name) != null) {
            HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvest.definition.0.already.exists",
                    name);
            throw new ForwardedToErrorPage("Harvest definition '" + name + "' already exists");
        }
        // Note, object/bytelimit set to default values, if not set
        hd = new FullHarvest(name, comments, oldHarvestId, objectLimit, byteLimit, runningtimeLimit, false,
                hdDaoProvider, jobDaoProvider, extendedFieldDAOProvider, domainDAOProvider);
        hd.setActive(false);
        hdDaoProvider.get().create(hd);
    } else {
        hd = (FullHarvest) hdDaoProvider.get().getHarvestDefinition(name);
        if (hd == null) {
            HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvest.0.does.not.exist", name);
            throw new UnknownID("Harvest definition '" + name + "' doesn't exist!");
        }
        long edition = HTMLUtils.parseOptionalLong(context, Constants.EDITION_PARAM, Constants.NO_EDITION);

        if (hd.getEdition() != edition) {
            HTMLUtils.forwardWithRawErrorMessage(context, i18n, "errormsg;harvest.definition.changed.0.retry.1",
                    "<br/><a href=\"Definitions-edit-snapshot-harvest.jsp?" + Constants.HARVEST_PARAM + "="
                            + HTMLUtils.encodeAndEscapeHTML(name) + "\">",
                    "</a>");

            throw new ForwardedToErrorPage("Harvest definition '" + name + "' has changed");
        }

        // MaxBytes is set to
        // dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_BYTES
        // if parameter snapshot_byte_Limit is not defined
        hd.setMaxBytes(byteLimit);

        // MaxCountObjects is set to
        // dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_OBJECTS
        // if parameter snapshot_object_limit is not defined
        hd.setMaxCountObjects(objectLimit);

        // MaxJobRunningTime is set to
        // dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_JOB_RUNNING_TIME
        // if parameter snapshot_time_limit is not defined
        hd.setMaxJobRunningTime(runningtimeLimit);

        hd.setPreviousHarvestDefinition(oldHarvestId);
        hd.setComments(comments);
        hdDaoProvider.get().update(hd);
    }
}

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

@RequiresRoles("admin")
@RequestMapping(value = "create", method = RequestMethod.POST)
public String create(@Valid ManageTask newManageTask, RedirectAttributes redirectAttributes,
        ServletRequest request) {
    String startDateStr = request.getParameter("startDateStr");
    String endDateStr = request.getParameter("endDateStr");
    try {//from w ww.  jav  a  2 s .com
        User user = new User(getCurrentUserId());
        newManageTask.setCreateDate(new Date());
        newManageTask.setStartDate(DateUtils.parseDate(startDateStr, "yyyy-MM-dd"));
        newManageTask.setEndDate(DateUtils.parseDate(endDateStr, "yyyy-MM-dd"));
        newManageTask.setUser(user);
        newManageTask.setIsdelete(0);
        newManageTask.setState("Y");
        manageTaskService.saveManageTask(newManageTask);

        if ("SELECT".equals(newManageTask.getViewrangeType())) {
            // ??
            String viewrangeUsers = request.getParameter("viewrangeUsers");
            if (!StringUtils.isEmpty(viewrangeUsers)) {
                String[] viewrangeUserArray = viewrangeUsers.split(",");
                for (int i = 0; i < viewrangeUserArray.length; i++) {
                    Long userId = Long.parseLong(viewrangeUserArray[i]);
                    User user_vr = new User(userId);
                    ViewRange vr = new ViewRange();
                    vr.setCreateDate(new Date());
                    vr.setIsdelete(0);
                    vr.setTask(newManageTask);
                    vr.setUser(user_vr);
                    manageTaskService.saveViewRange(vr);

                    User msUser = accountService.getUser(userId);
                    if (!StringUtils.isEmpty(msUser.getWeixinOpenid())) {
                        String AccessToken = manageTaskService.getAccessToken();
                        MobileHttpClient.sendWinXinMessage(AccessToken, msUser.getWeixinOpenid(),
                                "???,?!",
                                "", MobileContants.YM);
                    }
                }
            }
        }

        redirectAttributes.addFlashAttribute("message", "?");
        return "redirect:/manageTask/";
    } catch (Exception e) {
        e.printStackTrace();
        redirectAttributes.addFlashAttribute("message", "");
        return "redirect:/manageTask/";
    }
}

From source file:org.xwoot.mockiphone.web.MockIphoneSite.java

public Properties updatePropertiesFromRequest(ServletRequest request, String mockIphonePropertiesPath) {
    Properties p = getProperties(mockIphonePropertiesPath);
    if (!StringUtils.isEmpty(request.getParameter(MockIphoneSite.IWOOT_END_POINT))) {
        p.put(MockIphoneSite.IWOOT_END_POINT, request.getParameter(MockIphoneSite.IWOOT_END_POINT));
    }//from   w w w .  ja v a2  s.  co  m
    if (!StringUtils.isEmpty(request.getParameter(MockIphoneSite.MOCKIPHONE_DIR_NAME))) {
        p.put(MockIphoneSite.MOCKIPHONE_DIR_NAME, request.getParameter(MockIphoneSite.MOCKIPHONE_DIR_NAME));
    }
    return p;
}

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

@RequestMapping(value = "registerByUserCode", method = RequestMethod.POST)
public String registerByUserCode(@Valid User user, RedirectAttributes redirectAttributes,
        ServletRequest request) {
    user.setIsdelete(0);/*w w  w.  j av a  2 s  . co  m*/

    String activationCode = request.getParameter("activationCode");
    if (!StringUtils.isEmpty(activationCode)) {
        List<ActivationCode> codeList = activationCodeService.getActivationCodeByCode(activationCode);
        if (codeList != null && codeList.size() > 0) {
            ActivationCode code = codeList.get(0);
            if (!"CREATEUSER".equals(code.getActivationCodeType())) {
                redirectAttributes.addFlashAttribute("message", ",??");
                return "redirect:/register";
            }

            if ("disabled".equals(code.getStatus())) {
                user.setUpuser(code.getUser());
                user.setStatus("Audit");
                accountService.registerUser(user);

                redirectAttributes.addFlashAttribute("message",
                        "?,??,.");
                return "redirect:/login";
            } else {
                user.setUpuser(code.getUser());
                user.setStatus("enabled");
                accountService.registerUser(user);

                redirectAttributes.addFlashAttribute("message", "?.");
                return "redirect:/login";
            }
        } else {
            redirectAttributes.addFlashAttribute("message", ",??!");
            return "redirect:/register";
        }

    } else {
        redirectAttributes.addFlashAttribute("message", ",??!");
        return "redirect:/register";
    }

}