简体   繁体   中英

How can I get the service from a `HttpServletRequest` in Tomcat 8

How can I get the service from a HttpServletRequest in Tomcat 8?

In tomcat 7 mapper is in the Connector so I was able to access the Mapper as

((Request) request).getConnector().getMapper() //request is a HttpServletRequest

But how can I obtain this in Tomcat 8? In the tomcat 8 migration documentation it is said that

The Mapper has moved from the Connector to the Service since the Mapper is identical for all Connectors of a given Service.

The tomcat developers just moved the mapper to Service . So use:

((Request) request).getConnector().getService().getMapper()
public static String getFullURL(HttpServletRequest request) {
StringBuffer requestURL = request.getRequestURL();
String queryString = request.getQueryString();

if (queryString == null) {
    return requestURL.toString();
} else {
    return requestURL.append('?').append(queryString).toString();
}

}

最后,我找到了必须从连接器获取服务的方式

getConnector().getService().getMapper()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM