Example usage for javax.servlet.http HttpServletRequest getParameter

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

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest 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.stratelia.silverpeas.pdcPeas.servlets.PdcSearchRequestRouterHelper.java

/**
 * Build information for the home jsp for the advancedsearch plain text. We get user choices about
 * advanced search and store it in the PdcSearchSessionController
 *
 * @param pdcSC: the pdcSessionController
 * @param request : the HttpServletRequest
 * @return a QueryParameters from session updated with data from request
 * @throws Exception//from w  w  w.  j  a va2s .c  om
 */
public static QueryParameters saveUserChoices(PdcSearchSessionController pdcSC, HttpServletRequest request)
        throws Exception {
    String query = request.getParameter("query");

    QueryParameters queryParameters = pdcSC.getQueryParameters();
    queryParameters.setKeywords(query);

    if (pdcSC.getSearchType() >= PdcSearchSessionController.SEARCH_ADVANCED) {
        String lang = pdcSC.getLanguage();
        queryParameters.setSpaceIdAndInstanceId(request.getParameter("spaces"),
                request.getParameter("componentSearch"));
        queryParameters.setCreatorId(request.getParameter("authorSearch"));
        queryParameters.setAfterDate(getDateFromRequest("createafterdate", lang, request));
        queryParameters.setBeforeDate(getDateFromRequest("createbeforedate", lang, request));
        queryParameters.setAfterUpdateDate(getDateFromRequest("updateafterdate", lang, request));
        queryParameters.setBeforeUpdateDate(getDateFromRequest("updatebeforedate", lang, request));
        queryParameters.setFolder(request.getParameter(QueryParameters.PARAM_FOLDER));
    }

    String paramNbResToDisplay = request.getParameter("nbRes");
    if (paramNbResToDisplay != null) {
        int nbResToDisplay = Integer.parseInt(paramNbResToDisplay);
        pdcSC.setNbResToDisplay(nbResToDisplay);
    }
    String paramSortRes = request.getParameter("sortRes");
    if (paramSortRes != null) {
        int sortRes = Integer.parseInt(paramSortRes);
        pdcSC.setSortValue(sortRes);
    }
    String paramSortOrder = request.getParameter("sortOrder");
    if (paramSortOrder != null) {
        pdcSC.setSortOrder(paramSortOrder);
    }
    String paramSortResFieldXForm = request.getParameter(Keys.RequestSortXformField.value());
    if (StringUtil.isDefined(paramSortResFieldXForm)) {
        pdcSC.setXmlFormSortValue(paramSortResFieldXForm);
    } else {
        pdcSC.setXmlFormSortValue(null);
    }
    String sortImplementor = request.getParameter(Keys.RequestSortImplementor.value());
    if (StringUtil.isDefined(sortImplementor)) {
        pdcSC.setSortImplemtor(sortImplementor);
    } else {
        pdcSC.setSortImplemtor(null);
    }

    // Set component search type
    pdcSC.setDataType(request.getParameter("dataType"));
    return queryParameters;
}

From source file:com.liusoft.dlog4j.action.ActionBase.java

/**
 * ??validateSiteOwner??/*from  w ww  . j  av  a  2 s. c  om*/
 * @param req
 * @return
 */
protected static SiteBean getSiteBean(HttpServletRequest req) {
    SiteBean site = (SiteBean) req.getAttribute(KEY_SITE);
    if (site == null) {
        try {
            int site_id = Integer.parseInt(req.getParameter(Globals.PARAM_SID));
            site = SiteDAO.getSiteByID(site_id);
            if (site != null)
                req.setAttribute(KEY_SITE, site);
        } catch (Exception e) {
        }
    }
    return site;
}

From source file:com.attribyte.essem.util.Util.java

/**
 * Creates a metric key from request parameters.
 * @param request The request.//from   w w  w  .j  av a2  s.c  om
 * @return The created key.
 */
public static MetricKey createKey(final HttpServletRequest request) {

    String app = request.getParameter(Fields.APPLICATION_FIELD);
    if (app == null) {
        app = request.getParameter("app");
    }

    return new MetricKey(request.getParameter(Fields.NAME_FIELD), app, request.getParameter(Fields.HOST_FIELD),
            request.getParameter(Fields.INSTANCE_FIELD), request.getParameter("field"));
}

From source file:edu.stanford.muse.webapp.Sessions.java

public static Pair<Boolean, String> exportArchive(HttpServletRequest request) throws Exception {
    HttpSession session = request.getSession();

    Archive archive = JSPHelper.getArchive(session);
    String title = request.getParameter("title");
    String base_dir = System.getProperty("user.home") + java.io.File.separator + "muse." + title;
    String session_name = "default";

    boolean succeeded = false;
    String message = "";

    Collection<EmailDocument> emailDocs = (Collection<EmailDocument>) JSPHelper.getSessionAttribute(session,
            "emailDocs");
    if (emailDocs != null) {
        boolean trimArchive = request.getParameter("trimArchive") != null;
        boolean forPublicMode = request.getParameter("forPublicMode") != null;
        /* UNDESIRABLE as this will permanently change the index.
        if (trimArchive) {/*from  w  w w.jav  a  2s .co m*/
           archive.trimArchive(emailDocs); // fine if its null, nothing will be done (shouldn't happen)
        }
        */
        String dir = archive.export(trimArchive ? emailDocs : archive.getAllDocs(),
                forPublicMode ? true : false, base_dir, session_name);
        // TODO: may choose to invalidate session here since the state of archive has already changed
        succeeded = dir != null;
        if (!succeeded)
            message = "Archive export failed";
        else
            message = "Archive successfully exported to " + dir;
    } else {
        message = "No messages in this session";
    }

    return new Pair<Boolean, String>(succeeded, message);
}

From source file:com.tek271.reverseProxy.servlet.ProxyFilter.java

private static MultipartEntity getMultipartEntity(HttpServletRequest request) {
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    Enumeration<String> en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String name = en.nextElement();
        String value = request.getParameter(name);
        try {//from  w w w.j  ava  2 s.  c  om
            if (name.equals("file")) {
                FileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setSizeMax(10000000);// 10 Mo
                List items = upload.parseRequest(request);
                Iterator itr = items.iterator();
                while (itr.hasNext()) {
                    FileItem item = (FileItem) itr.next();
                    File file = new File(item.getName());
                    FileOutputStream fos = new FileOutputStream(file);
                    fos.write(item.get());
                    fos.flush();
                    fos.close();
                    entity.addPart(name, new FileBody(file, "application/zip"));
                }
            } else {
                entity.addPart(name, new StringBody(value.toString(), "text/plain", Charset.forName("UTF-8")));
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (FileUploadException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (FileNotFoundException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }

    return entity;

}

From source file:com.healthcit.analytics.dao.CouchDBDaoUtils.java

/**
 * Constructs a URL-encoded String of request parameters from a set of parameter key/value pairs.
 * @param paramKeys//from   w  w  w. ja  v  a  2  s .c o m
 * @param paramValues
 * @return
 */
@SuppressWarnings("unchecked")
public static String constructParameterList(HttpServletRequest request) {
    Enumeration<String> requestParamNames = request.getParameterNames();

    List<String> names = new ArrayList<String>();

    List<String> values = new ArrayList<String>();

    while (requestParamNames.hasMoreElements()) {
        String element = requestParamNames.nextElement();

        if (ArrayUtils.contains(STANDARD_COUCHDB_PARAM_NAMES, element)) {
            names.add(element);

            values.add(request.getParameter(element));
        }
    }

    StringBuffer str = new StringBuffer();

    if (names != null && names.size() == values.size()) {
        for (int i = 0; i < names.size(); ++i) {
            if (i > 0)
                str.append("&");

            String key = names.get(i);

            String value = values.get(i);

            str.append(key);

            str.append("=");

            try {
                str.append(URLEncoder.encode(value, UTF8));
            } catch (UnsupportedEncodingException e) {
            }
        }
    }
    return str.toString();
}

From source file:ch.cern.security.saml2.utils.UrlUtils.java

/**
 * Preprocess the request and invokes the verification:
 * // w w  w .j av  a  2s  .  c  o  m
 * @param request
 * @param isDebugEnabled
 * @return
 * @throws Exception
 */
public static boolean verify(HttpServletRequest request, boolean isDebugEnabled) throws Exception {

    StringBuffer data = new StringBuffer();
    String sigAlg = null;
    String signature = null;
    data.append(Constants.SAML_REQUEST);
    data.append(EQUAL);

    if (isDebugEnabled)
        nc.notice("Query String: " + request.getQueryString());

    if (request.getParameter(Constants.SAML_REQUEST) != null) {
        if (isDebugEnabled)
            nc.notice(request.getParameter(Constants.SAML_REQUEST));
        data.append(LogoutUtils.urlEncode(request.getParameter(Constants.SAML_REQUEST),
                Constants.CHARACTER_ENCODING));
    } else {
        nc.error("NO " + Constants.SAML_REQUEST + " parameter");
        throw new Exception("NO " + Constants.SAML_REQUEST + " parameter");
    }

    // Get the sigAlg, it should match with the one declared as context
    // param
    sigAlg = request.getParameter(Constants.SIG_ALG);
    if (isDebugEnabled)
        nc.notice(sigAlg);
    if (((String) request.getSession().getServletContext().getAttribute(Constants.SIG_ALG)).equals(sigAlg)) {
        data.append(AMPERSAND);
        data.append(Constants.SIG_ALG);
        data.append(EQUAL);
        data.append(LogoutUtils.urlEncode(sigAlg, Constants.CHARACTER_ENCODING));
    } else {
        throw new NoSuchAlgorithmException();
    }

    // Get the signature and decode it in Base64
    Base64 base64 = new Base64();
    if (request.getParameter(SIGNATURE) != null) {
        if (isDebugEnabled)
            nc.notice("Signature: " + request.getParameter(SIGNATURE));
        signature = request.getParameter(SIGNATURE);
    } else {
        nc.error("NO " + SIGNATURE + " parameter");
        throw new Exception("NO " + SIGNATURE + " parameter");
    }

    if (isDebugEnabled)
        nc.notice("Data to verify: " + data.toString());

    // Verify
    return SignatureUtils.verify(data.toString().getBytes(), (byte[]) base64.decode(signature.getBytes()),
            (PublicKey) request.getSession().getServletContext().getAttribute(Constants.IDP_PUBLIC_KEY));
}

From source file:architecture.ee.web.util.ParamUtils.java

/**
* request String //  w w  w  .  j a  va  2s  .c  om
* @param request
* @return
*/
public static void printParameter(HttpServletRequest request, Log log) {
    StringBuilder sb = new StringBuilder();
    Enumeration e = request.getParameterNames();

    sb.append("\n ==================== printParameter ====================");
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = request.getParameter(key);
        sb.append("\n ==== " + key + " : " + value + " ");
    }
    sb.append("\n ==================== printParameter ====================\n");

    //return sb.toString();
    log.debug(sb);
}

From source file:com.liangc.hq.base.utils.AlertDefUtil.java

/**
 * Retrieve the alert definition from either the request or from the bizapp
 * as necessary. First check to see if the alertDef is already in the
 * request attributes. If it is, return it. If not, look for an "ad"
 * parameter and then get the alert definition from the bizapp and return
 * it.//  w w  w  . java 2s.  co  m
 */
public static AlertDefinitionValue getAlertDefinition(HttpServletRequest request, int sessionID, EventsBoss eb)
        throws Exception {
    AlertDefinitionValue adv = (AlertDefinitionValue) request.getAttribute(Constants.ALERT_DEFINITION_ATTR);
    if (null == adv) {
        String adS = request.getParameter(Constants.ALERT_DEFINITION_PARAM);
        if (null == adS) {
            throw new Exception(Constants.ALERT_DEFINITION_PARAM);
        } else {
            Integer ad = new Integer(adS);
            adv = eb.getAlertDefinition(sessionID, ad);
            request.setAttribute(Constants.ALERT_DEFINITION_ATTR, adv);
        }
        log.trace("adv.id=" + adv.getId());
    }

    return adv;
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagHelper.java

/**
 * Checks if any of the list actions were clicked like
 * selectAll, unselectAll update set, pagination buttons (in which
 * page_action will be returned).. etc/*from   w  ww .  ja v a  2s .c  o  m*/
 * and returns the appropriate value
 * @param listName name of list
 * @param request active HttpServletRequest
 * @return List Action if any of the list actions were selected
 *         null if not.
 */

public static String getListAction(String listName, HttpServletRequest request) {
    String uniqueName = TagHelper.generateUniqueName(listName);
    if (DataSetManipulator.getPaginationParam(request, uniqueName) != null
            || PageSizeDecorator.pageWidgetSelected(request, listName)) {
        return PAGE_ACTION;
    }

    String fieldParam = ListTagUtil.makeSelectActionName(uniqueName);
    return request.getParameter(fieldParam);
}