如何从HttpServletRequest获取完整的URL?

时间:2014-05-16 04:58:09

标签: java servlets

好的,我有这些代码:

HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestQueryString = httpRequest.getQueryString();
System.out.println(requestQueryString);

打开网址“http://127.0.0.1:8888/MyProject.html?gwt.codesvr=127.0.0.1:9997?_escaped_fragment_=home”时,

打印出来了:

 gwt.codesvr=127.0.0.1:9997?_escaped_fragment_=home

该网址缺少http://127.0.0.1:8888/MyProject.html?部分。

如何解决?

1 个答案:

答案 0 :(得分:3)

这将是

httpRequest.getRequestURL() + "?" + httpRequest.getQueryString()

打印

http://127.0.0.1:8888/MyProject.html?gwt.codesvr=127.0.0.1:9997?_escaped_fragment_=home