本文整理匯總了Java中javax.servlet.ServletRequest.getServerName方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletRequest.getServerName方法的具體用法?Java ServletRequest.getServerName怎麽用?Java ServletRequest.getServerName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.ServletRequest
的用法示例。
在下文中一共展示了ServletRequest.getServerName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doFilter
import javax.servlet.ServletRequest; //導入方法依賴的package包/類
/**
* Rewrites the outgoing stream to make sure URLs and headers
* are correct. The incoming request is first processed to
* identify what resource we want to proxy.
*
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
if (response.isCommitted()) {
log.info("Not proxying, already committed.");
return;
} else if (!(request instanceof HttpServletRequest)) {
log.info("Request is not HttpRequest, will only handle HttpRequests.");
return;
} else if (!(response instanceof HttpServletResponse)) {
log.info("Request is not HttpResponse, will only handle HttpResponses.");
return;
} else {
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpServletRequest httpRequest = (HttpServletRequest) request;
Server server = serverChain.evaluate(httpRequest);
if (server == null) {
log.info("Could not find a rule for this request, will not do anything.");
filterChain.doFilter(request, response);
} else {
httpRequest.setAttribute("proxyServer", server);
String ownHostName = request.getServerName() + ":" + request.getServerPort();
UrlRewritingResponseWrapper wrappedResponse;
wrappedResponse = new UrlRewritingResponseWrapper(httpResponse, server, ownHostName, httpRequest.getContextPath(), serverChain);
filterChain.doFilter(httpRequest, wrappedResponse);
wrappedResponse.processStream();
}
}
}