當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletRequest.getQueryString方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getQueryString方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getQueryString方法的具體用法?Java HttpServletRequest.getQueryString怎麽用?Java HttpServletRequest.getQueryString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getQueryString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Set the request that we are wrapping.
 *
 * @param request The new wrapped request
 */
void setRequest(HttpServletRequest request) {

    super.setRequest(request);

    // Initialize the attributes for this request
    dispatcherType = (DispatcherType)request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
    requestDispatcherPath = 
        request.getAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR);

    // Initialize the path elements for this request
    contextPath = request.getContextPath();
    pathInfo = request.getPathInfo();
    queryString = request.getQueryString();
    requestURI = request.getRequestURI();
    servletPath = request.getServletPath();

}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:23,代碼來源:ApplicationHttpRequest.java

示例2: doGet

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  InputStreamReader in = new InputStreamReader(request.getInputStream());
  PrintStream out = new PrintStream(response.getOutputStream());

  calledTimes++;
  try {
    requestUri = new URI(null, null,
        request.getRequestURI(), request.getQueryString(), null);
    foundJobState = request.getParameter("status");
  } catch (URISyntaxException e) {
  }

  in.close();
  out.close();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestJobEndNotifier.java

示例3: onAccessDenied

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    StringBuffer sso_server_url = new StringBuffer(PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.sso.server.url"));
    // server需要登錄
    String upmsType = PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.type");
    if ("server".equals(upmsType)) {
        WebUtils.toHttp(response).sendRedirect(sso_server_url.append("/sso/login").toString());
        return false;
    }
    sso_server_url.append("/sso/index").append("?").append("appid").append("=").append(PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.appID"));
    // 回跳地址
    HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
    StringBuffer backurl = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        backurl.append("?").append(queryString);
    }
    sso_server_url.append("&").append("backurl").append("=").append(URLEncoder.encode(backurl.toString(), "utf-8"));
    WebUtils.toHttp(response).sendRedirect(sso_server_url.toString());
    return false;
}
 
開發者ID:sunzhen086,項目名稱:lambo,代碼行數:22,代碼來源:UpmsAuthenticationFilter.java

示例4: resolveException

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) {
    if (exception instanceof FlowExecutionRepositoryException && !(exception instanceof BadlyFormattedFlowExecutionKeyException)) {
        String urlToRedirectTo = request.getRequestURI() + (request.getQueryString() != null ? '?' + request.getQueryString() : "");
        log.debug("Error getting flow information for URL [{}]", urlToRedirectTo, exception);
        Map<String, Object> model = new HashMap();
        model.put(this.modelKey, StringEscapeUtils.escapeHtml4(exception.getMessage()));
        return new ModelAndView(new RedirectView(urlToRedirectTo), model);
    } else if (exception instanceof AbstractFlowExecutionException) {
        if (log.isDebugEnabled()) {
            log.error("Flow execution error", exception);
        } else {
            log.error("Flow execution error: {}", exception.getMessage());
        }
        return ((AbstractFlowExecutionException) exception).getModelAndView();
    } else {
        log.debug("Ignoring the received exception due to a type mismatch", exception);
        return null;
    }
}
 
開發者ID:e-gov,項目名稱:TARA-Server,代碼行數:20,代碼來源:FlowExecutionExceptionResolver.java

示例5: doGet

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest req, HttpServletResponse res)
  throws ServletException, IOException {
  String queryString = req.getQueryString();
  switch (counter) {
    case 0:
      verifyQuery(queryString, "SUCCEEDED");
      break;
    case 2:
      verifyQuery(queryString, "KILLED");
      break;
    case 4:
      verifyQuery(queryString, "FAILED");
      break;
  }
  if (counter % 2 == 0) {
    res.sendError(HttpServletResponse.SC_BAD_REQUEST, "forcing error");
  }
  else {
    res.setStatus(HttpServletResponse.SC_OK);
  }
  counter++;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:NotificationTestCase.java

示例6: getFullRequestUrl

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Returns the full request URL for a servlet request.
 *
 * 1) Fixes HTTPS protocol if forwarded by load balancer.
 * 2) Handles query strings.
 *
 * See:
 * http://stackoverflow.com/a/2222268/2051724
 * http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html
 *
 * @param request The original HTTP servlet request.
 * @return The full request URL.
 */
public static URI getFullRequestUrl(final HttpServletRequest request) {
    if (request == null) {
        return null;
    }

    String url = request.getRequestURL().toString();

    // Fix HTTPS->HTTP rewriting from HTTP proxy.
    // For example, "https://www.ajibot.com" will appear as "http://www.ajibot.com"
    final String forwarded = request.getHeader("X-Forwarded-Proto");
    if (forwarded != null && forwarded.equals("https")) {
        url = url.replaceFirst("http://", "https://");
    }

    final String queryString = request.getQueryString();
    if (queryString != null) {
        url += "?" + queryString;
    }

    return URI.create(url);
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:35,代碼來源:UrlUtils.java

示例7: resolveException

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public ModelAndView resolveException(final HttpServletRequest request,
    final HttpServletResponse response, final Object handler,
    final Exception exception) {

    /*
     * Since FlowExecutionRepositoryException is a common ancestor to these exceptions and other
     * error cases we would likely want to hide from the user, it seems reasonable to check for
     * FlowExecutionRepositoryException.
     *
     * BadlyFormattedFlowExecutionKeyException is specifically ignored by this handler
     * because redirecting to the requested URI with this exception may cause an infinite
     * redirect loop (i.e. when invalid "execution" parameter exists as part of the query string
     */
    if (!(exception instanceof FlowExecutionRepositoryException)
          || exception instanceof BadlyFormattedFlowExecutionKeyException) {
        logger.debug("Ignoring the received exception due to a type mismatch", exception);
        return null;
    }

    final String urlToRedirectTo = request.getRequestURI()
            + (request.getQueryString() != null ? '?'
            + request.getQueryString() : "");

    logger.debug("Error getting flow information for URL [{}]", urlToRedirectTo, exception);
    final Map<String, Object> model = new HashMap<>();
    model.put(this.modelKey, StringEscapeUtils.escapeHtml4(exception.getMessage()));

    return new ModelAndView(new RedirectView(urlToRedirectTo), model);
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:31,代碼來源:FlowExecutionExceptionResolver.java

示例8: getRequestURL

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/** Reconstruct the requested URL, complete with query string (if any). */
public static String getRequestURL(HttpServletRequest request) {
    StringBuffer url = request.getRequestURL();
    String queryString = request.getQueryString();
    if (queryString != null) {
        url.append("?").append(queryString);
    }
    return url.toString();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:OAuthServlet.java

示例9: getOriginatingQueryString

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Return the query string part of the given request's URL. If this is a forwarded request,
 * correctly resolves to the query string of the original request.
 * @param request current HTTP request
 * @return the query string
 */
public String getOriginatingQueryString(HttpServletRequest request) {
	if ((request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) != null) ||
		(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE) != null)) {
		return (String) request.getAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE);
	}
	else {
		return request.getQueryString();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:UrlPathHelper.java

示例10: logReq

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Print logs of http request.
 */
public static void logReq(Logger logger, HttpServletRequest req) {
    String queryStr = req.getQueryString();
    if (queryStr == null || queryStr.length() == 0) {
        logger.info(req.getMethod() + " " + req.getRequestURI());
    } else {
        try {
            queryStr = URLDecoder.decode(queryStr, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            logger.warn(e.getMessage());
        }
        logger.info(req.getMethod() + " " + req.getRequestURI() + "?" + queryStr);
    }
}
 
開發者ID:AwesomeTickets,項目名稱:ServiceServer,代碼行數:17,代碼來源:LogUtil.java

示例11: doGet

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
                  throws IOException, ServletException {

    String query = request.getQueryString();

    if ((query == null) || (query.length() == 0)) {
        response.setContentType("text/html");

        // [email protected] 20020130 - patch 1.7.0 by fredt
        // to avoid caching on the browser
        response.setHeader("Pragma", "no-cache");

        PrintWriter out = response.getWriter();

        out.println(
            "<html><head><title>HSQL Database Engine Servlet</title>");
        out.println("</head><body><h1>HSQL Database Engine Servlet</h1>");
        out.println("The servlet is running.<p>");

        if (initError == null) {
            out.println("Connected to the database.<p>");
            out.println("Database name: " + dbType + dbPath + "<p>");
        } else {
            out.println("<h2>The database is not available.</h2>");
            out.println("The error message is:<p>");
            out.println(initError);
        }

        out.println("</body></html>");
    }
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:33,代碼來源:Servlet.java

示例12: log

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private void log(HttpServletRequest request, HttpServletResponse response) {
    long duration = 0;
    try {
        final Long requestStartTime = (Long) request.getAttribute(START_TIME);
        if (requestStartTime!=null && requestStartTime > 0) {
            duration = System.currentTimeMillis() - requestStartTime;
        }
    } catch (Exception x) {
        log.warn("Could not get request start time {}", x);
    }

    final StringBuilder httpHeaders = new StringBuilder('[');
    for (final Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements(); ) {
        final String headerName = headerNames.nextElement();
        httpHeaders.append('[').append(headerName).append(": ").append(request.getHeader(headerName)).append("], ");
    }
    httpHeaders.append(']');

    final StringBuffer requestStringBuffer = request.getRequestURL();

    if (request.getQueryString() != null && !request.getQueryString().isEmpty()) {
        requestStringBuffer.append("?").append(request.getQueryString());
    }

    Metrics.reportGatewayRedirectDurationStats(duration);

    log.info("Request: {} {} agent={} status={} duration={} HTTP Headers={}",
            request.getMethod(), requestStringBuffer,
            request.getHeader("User-Agent"),
            response.getStatus(),
            duration != 0 ? duration : "unknown",
            httpHeaders.toString());
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:34,代碼來源:AccessLoggingFilter.java

示例13: rootController

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Bean
protected Controller rootController() {
    return new ParameterizableViewController() {
        protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
            String queryString = request.getQueryString();
            String url = request.getContextPath() + "/login" + (queryString != null ? '?' + queryString : "");
            return new ModelAndView(new RedirectView(response.encodeURL(url)));
        }
    };
}
 
開發者ID:e-gov,項目名稱:TARA-Server,代碼行數:11,代碼來源:CasWebAppConfiguration.java

示例14: getFullRequestUrl

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/***
 * 獲取請求的完整url路徑 比如http://car.chexiang.com/detail.htm?spuId=2222
 * @param request
 * @param needQueryString 是否包含get請求的參數
 * @return
 */
public static String getFullRequestUrl(HttpServletRequest request, boolean needQueryString){
	StringBuilder urlBuilder = new StringBuilder();
	urlBuilder.append(request.getRequestURL().toString());
	if(needQueryString){
		if(request.getQueryString() != null && request.getQueryString().length() > 0){
			urlBuilder.append("?").append(request.getQueryString());
		}
	}
	return urlBuilder.toString();
}
 
開發者ID:tojaoomy,項目名稱:private-WeChat,代碼行數:17,代碼來源:RequestUtils.java

示例15: redirectToLogon

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private void redirectToLogon(HttpServletRequest request, HttpServletResponse response) {
    try {
        String referer = request.getHeader("Referer");
        String recoveryUrlParams = "";
        //get request parameters
        if (has(referer) && referer.contains("?")) {
            recoveryUrlParams = referer.substring(referer.lastIndexOf("?") + 1);
        } else {
            recoveryUrlParams = request.getQueryString();
        }
        //saves page where user were
        String requestedPage = request.getRequestURI();
        StringBuilder recoveryUrl = null;
        if (!loginPage.equals(requestedPage) && requestedPage.contains(".")) {
            if (requestedPage.startsWith(request.getContextPath())) {
                requestedPage = requestedPage.replaceFirst(request.getContextPath(), "");
            }
            recoveryUrl = new StringBuilder(requestedPage);
            if (has(recoveryUrlParams)) {
                recoveryUrl.append("?").append(recoveryUrlParams);
            }
        }
        /*
         if saved page is not null and is not index page then send user to logon page and save
        / previous page in url param named 'page'
        */
        String redirectUrl = request.getContextPath() + "/" + loginPage + (has(recoveryUrl) &&
                isValidRecoveryUrl(recoveryUrl) ? "?page=" + URLEncoder.encode(recoveryUrl.toString(), "UTF-8") : "");
        if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
            //redirect on ajax request: //http://stackoverflow.com/questions/13366936/jsf-filter-not-redirecting-after-initial-redirect
            response.setContentType("text/xml");
            response.getWriter()
                    .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
                    .printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", redirectUrl);
        } else {//normal redirect
            response.sendRedirect(redirectUrl);
        }

    } catch (Exception e) {
        log.log(Level.SEVERE,"Could not redirect to " + loginPage, e);
    }

}
 
開發者ID:adminfaces,項目名稱:admin-template,代碼行數:44,代碼來源:AdminFilter.java


注:本文中的javax.servlet.http.HttpServletRequest.getQueryString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。