本文整理汇总了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();
}
}
}