use*_*173 5 java spring tomcat
我正在Spring MVC控制器中构建一个新的URL,以传递回客户端.目前我正在尝试这个:
// httpRequest is the current HttpServletRequest
new URL(httpRequest.getProtocol(),
httpRequest.getServerName(),
httpRequest.getServerPort(),
httpRequest.getContextPath().concat("/foo/bar.html"));
Run Code Online (Sandbox Code Playgroud)
问题是httpRequest.getProtocol()给我"HTTP/1.1"而不仅仅是"HTTP".我可以修剪它,但想知道是否有更优雅的方式.
ζ--*_*ζ-- 12
协议是HTTP/1.1,因为它是HTTP的特定版本.该方案ServletRequest#getScheme本身就是http:
new URL(httpRequest.getScheme(),
httpRequest.getServerName(),
httpRequest.getServerPort(),
httpRequest.getContextPath().concat("/foo/bar.html"));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5561 次 |
| 最近记录: |