Example usage for javax.servlet.http HttpServletRequest getQueryString

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

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getQueryString.

Prototype

public String getQueryString();

Source Link

Document

Returns the query string that is contained in the request URL after the path.

Usage

From source file:com.acciente.commons.htmlform.Parser.java

/**
 * This method parses all the parameters contained in the http servlet request, in particular it parses and
 * merges parameters from the sources listed below. If a parameter is defined in more than on source the higher
 * numbered source below prevails./*www.ja v  a2  s  .c o m*/
 *
 *    1  - parameters in the URL's query query string (GET params)
 *    2  - parameters submitted using POST including multi-part parameters such as fileuploads
 *
 * @param oRequest a http servlet request object
 * @param iStoreFileOnDiskThresholdInBytes a file size in bytes above which the uploaded file will be stored on disk
 * @param oUploadedFileStorageDir a File object representing a path to which the uploaded files should be saved,
 * if null is specified a temporary directory is created in the java system temp directory path
 *
 * @return a map containing the paramater names and values, the paramter names are keys in the map
 *
 * @throws ParserException thrown if there is an error parsing the parameter data
 * @throws IOException thrown if there is an I/O error
 * @throws FileUploadException thrown if there is an error processing the multi-part data
 */
public static Map parseForm(HttpServletRequest oRequest, int iStoreFileOnDiskThresholdInBytes,
        File oUploadedFileStorageDir) throws ParserException, IOException, FileUploadException {
    Map oGETParams = null;

    // first process the GET parameters (if any)
    if (oRequest.getQueryString() != null) {
        oGETParams = parseGETParams(oRequest);
    }

    Map oPOSTParams = null;

    // next process POST parameters
    if ("post".equals(oRequest.getMethod().toLowerCase())) {
        // check how the POST data has been encoded
        if (ServletFileUpload.isMultipartContent(oRequest)) {
            oPOSTParams = parsePOSTMultiPart(oRequest, iStoreFileOnDiskThresholdInBytes,
                    oUploadedFileStorageDir);
        } else {
            // we have plain text
            oPOSTParams = parsePOSTParams(oRequest);
        }
    }

    Map oMergedParams;

    // merge the GET and POST parameters
    if (oGETParams != null) {
        oMergedParams = oGETParams;

        if (oPOSTParams != null) {
            oMergedParams.putAll(oPOSTParams);
        }
    } else {
        // we know that the oGETParams must be null
        oMergedParams = oPOSTParams;
    }

    return oMergedParams;
}

From source file:ch.entwine.weblounge.common.url.UrlUtils.java

/**
 * Returns the request url as a string./*ww  w.j a v  a  2s .com*/
 * 
 * @param request
 *          the request
 * @param includePath
 *          <code>true</code> to also include the request uri
 * @param includeQuery
 *          <code>true</code> to include the query string
 * @return the url as a string
 */
public static URL toURL(HttpServletRequest request, boolean includePath, boolean includeQuery) {
    try {
        StringBuffer buf = new StringBuffer(request.getScheme());
        buf.append("://");
        buf.append(request.getServerName());
        if (request.getServerPort() != 80)
            buf.append(":").append(request.getServerPort());
        if (includePath && request.getRequestURI() != null)
            buf.append(request.getRequestURI());
        if (includeQuery && StringUtils.isNotBlank(request.getQueryString()))
            buf.append(request.getQueryString());
        return new URL(buf.toString());
    } catch (MalformedURLException e) {
        throw new IllegalStateException(e);
    }
}

From source file:net.yacy.http.ProxyHandler.java

public final static synchronized void logProxyAccess(HttpServletRequest request) {

    final StringBuilder logMessage = new StringBuilder(80);

    // Timestamp/*from ww  w .ja va  2s  . c o m*/
    logMessage.append(GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()));
    logMessage.append(' ');

    // Remote Host
    final String clientIP = request.getRemoteAddr();
    logMessage.append(clientIP);
    logMessage.append(' ');

    // Method
    final String requestMethod = request.getMethod();
    logMessage.append(requestMethod);
    logMessage.append(' ');

    // URL
    logMessage.append(request.getRequestURL());
    final String requestArgs = request.getQueryString();
    if (requestArgs != null) {
        logMessage.append("?").append(requestArgs);
    }

    HTTPDProxyHandler.proxyLog.fine(logMessage.toString());

}

From source file:eionet.cr.web.util.JstlFunctions.java

/**
 * Returns a string that is constructed by concatenating the given bean request's getRequestURI() + "?" + the given bean
 * request's getQueryString(), and replacing the sort predicate with the given one. The present sort order is replaced by the
 * opposite.// w  w w. jav a  2s . c  o m
 *
 * @param request
 * @param sortP
 * @param sortO
 * @return
 */
public static String sortUrl(AbstractActionBean actionBean, SearchResultColumn column) {

    HttpServletRequest request = actionBean.getContext().getRequest();
    StringBuffer buf = new StringBuffer(actionBean.getUrlBinding());
    buf.append("?");
    if (StringUtils.isBlank(column.getActionRequestParameter())) {

        if (!StringUtils.isBlank(request.getQueryString())) {

            QueryString queryString = QueryString.createQueryString(request);
            queryString.removeParameters(actionBean.excludeFromSortAndPagingUrls());
            buf.append(queryString.toURLFormat());
        }
    } else {
        buf.append(column.getActionRequestParameter());
    }

    String sortParamValue = column.getSortParamValue();
    if (sortParamValue == null) {
        sortParamValue = "";
    }

    String curValue = request.getParameter("sortP");
    if (curValue != null && buf.indexOf("sortP=") > 0) {
        buf = new StringBuffer(StringUtils.replace(buf.toString(), "sortP=" + Util.urlEncode(curValue),
                "sortP=" + Util.urlEncode(sortParamValue)));
    } else {
        buf.append("&amp;sortP=").append(Util.urlEncode(sortParamValue));
    }

    curValue = request.getParameter("sortO");
    if (curValue != null && buf.indexOf("sortO=") > 0) {
        buf = new StringBuffer(StringUtils.replace(buf.toString(), "sortO=" + curValue,
                "sortO=" + SortOrder.oppositeSortOrder(curValue)));
    } else {
        buf.append("&amp;sortO=").append(SortOrder.oppositeSortOrder(curValue));
    }

    String result = buf.toString();
    return result.startsWith("/") ? result.substring(1) : result;
}

From source file:it.greenvulcano.gvesb.adapter.http.utils.DumpUtils.java

public static void dump(HttpServletRequest request, StringBuffer log) throws IOException {
    String hN;//from w w w . ja v a 2s  . co  m

    log.append("-- DUMP HttpServletRequest START").append("\n");
    log.append("Method             : ").append(request.getMethod()).append("\n");
    log.append("RequestedSessionId : ").append(request.getRequestedSessionId()).append("\n");
    log.append("Scheme             : ").append(request.getScheme()).append("\n");
    log.append("IsSecure           : ").append(request.isSecure()).append("\n");
    log.append("Protocol           : ").append(request.getProtocol()).append("\n");
    log.append("ContextPath        : ").append(request.getContextPath()).append("\n");
    log.append("PathInfo           : ").append(request.getPathInfo()).append("\n");
    log.append("QueryString        : ").append(request.getQueryString()).append("\n");
    log.append("RequestURI         : ").append(request.getRequestURI()).append("\n");
    log.append("RequestURL         : ").append(request.getRequestURL()).append("\n");
    log.append("ContentType        : ").append(request.getContentType()).append("\n");
    log.append("ContentLength      : ").append(request.getContentLength()).append("\n");
    log.append("CharacterEncoding  : ").append(request.getCharacterEncoding()).append("\n");

    log.append("---- Headers START\n");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        hN = headerNames.nextElement();
        log.append("[" + hN + "]=");
        Enumeration<String> headers = request.getHeaders(hN);
        while (headers.hasMoreElements()) {
            log.append("[" + headers.nextElement() + "]");
        }
        log.append("\n");
    }
    log.append("---- Headers END\n");

    log.append("---- Body START\n");
    log.append(IOUtils.toString(request.getInputStream())).append("\n");
    log.append("---- Body END\n");

    log.append("-- DUMP HttpServletRequest END \n");
}

From source file:com.feilong.servlet.http.RequestUtil.java

/**
 * ?./*w  w w  . j a v  a2s  .  c  o  m*/
 * 
 * <ul>
 * <li>request??queryString, requestURL(post)</li>
 * <li>request?queryString, requestURL+??queryString</li>
 * </ul>
 * 
 * @param request
 *            the request
 * @param charsetType
 *            ?, {@link CharsetType} ?
 * @return :http://localhost:8080/feilong/requestdemo.jsp?id=2
 */
public static String getRequestFullURL(HttpServletRequest request, String charsetType) {
    String requestURL = getRequestURL(request);
    String queryString = request.getQueryString();
    return isNullOrEmpty(queryString) ? requestURL
            : requestURL + QUESTIONMARK + decodeISO88591String(queryString, charsetType);
}

From source file:org.itracker.web.util.LoginUtilities.java

public static boolean checkAutoLogin(HttpServletRequest request, boolean allowSaveLogin) {
    boolean foundLogin = false;

    if (request != null) {
        int authType = getRequestAuthType(request);

        // Check for auto login in request
        if (authType == AuthenticationConstants.AUTH_TYPE_REQUEST) {
            String redirectURL = request.getRequestURI().substring(request.getContextPath().length())
                    + (request.getQueryString() != null ? "?" + request.getQueryString() : "");
            request.setAttribute(Constants.AUTH_TYPE_KEY, AuthenticationConstants.AUTH_TYPE_REQUEST);
            request.setAttribute(Constants.AUTH_REDIRECT_KEY, redirectURL);
            request.setAttribute("processLogin", "true");
            foundLogin = true;/*w ww.j a  v a2s  .c o m*/

        }

        // Add in check for client certs

        // Check for auto login with cookies, this will only happen if users
        // are allowed to save
        // their logins to cookies
        if (allowSaveLogin && !foundLogin) {
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if (Constants.COOKIE_NAME.equals(cookie.getName())) {
                        int seperator = cookie.getValue().indexOf('~');
                        final String login;
                        if (seperator > 0) {
                            login = cookie.getValue().substring(0, seperator);
                            if (logger.isDebugEnabled()) {
                                logger.debug("Attempting autologin for user " + login + ".");
                            }

                            String redirectURL = request.getRequestURI()
                                    .substring(request.getContextPath().length())
                                    + (request.getQueryString() != null ? "?" + request.getQueryString() : "");
                            request.setAttribute(Constants.AUTH_LOGIN_KEY,
                                    cookie.getValue().substring(0, seperator));
                            request.setAttribute(Constants.AUTH_TYPE_KEY,
                                    AuthenticationConstants.AUTH_TYPE_PASSWORD_ENC);

                            request.setAttribute(Constants.AUTH_VALUE_KEY,
                                    cookie.getValue().substring(seperator + 1));
                            request.setAttribute(Constants.AUTH_REDIRECT_KEY, redirectURL);
                            request.setAttribute("processLogin", "true");
                            foundLogin = true;
                        }
                    }
                }
            }
        }

    }

    return foundLogin;
}

From source file:org.frontcache.core.FCUtils.java

/**
 * /*w w  w  .j  a v a  2  s . c  o  m*/
 * @param request
 * @return
 */
public static String getRequestURL(HttpServletRequest request) {
    String requestURL = request.getRequestURL().toString();

    if ("GET".equals(request.getMethod())) {
        // add parameters for storing 
        // POST method parameters are not stored because they can be huge (e.g. file upload)
        StringBuffer sb = new StringBuffer(requestURL);
        if (!request.getParameterMap().isEmpty())
            sb.append("?").append(request.getQueryString());

        requestURL = sb.toString();
    }
    return requestURL;
}

From source file:com.tc.utils.XSPUtils.java

public static String getURL() {

    HttpServletRequest req = XSPUtils.getRequest();
    String scheme = req.getScheme(); // http
    String serverName = req.getServerName(); // hostname.com
    int serverPort = req.getServerPort(); // 80
    String contextPath = req.getContextPath(); // /mywebapp
    String servletPath = req.getServletPath(); // /servlet/MyServlet
    String pathInfo = req.getPathInfo(); // /a/b;c=123
    String queryString = req.getQueryString(); // d=789

    // Reconstruct original requesting URL
    StringBuffer url = new StringBuffer();
    url.append(scheme).append("://").append(serverName);

    if ((serverPort != 80) && (serverPort != 443)) {
        url.append(":").append(serverPort);
    }// w w w.  j av a 2  s  . c  om

    url.append(contextPath).append(servletPath);

    if (pathInfo != null) {
        url.append(pathInfo);
    }
    if (queryString != null) {
        url.append("?").append(queryString);
    }
    return url.toString();
}

From source file:org.davidmendoza.esu.web.DialogaController.java

@RequestMapping(method = RequestMethod.GET)
public String dialoga(HttpServletRequest request) {
    log.info("Redirecting: /dialoga?{}", request.getQueryString());
    return "redirect:/profundiza";
}