request得到帶引數的請求url
阿新 • • 發佈:2019-02-08
//Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request
// eg. /manage/editExam.domethod=goExamSet&type=U
String url = request.getRequestURI();
//The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters
String fullPath = url + queryString; // 或者是url_buffer.toString()+queryString;
String url = request.getRequestURI();
//The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters
HttpServletRequest 的這兩種方法都只能得到不包含引數的請求url,區別如下:
1 前者返回相對路徑,後者返回完整路徑
2 前者返回string ,後者返回stringbuffer
要想得到完整請求url可以通過如下方法,getQueryString()得到的是url後面的引數串,和前者相加就是帶引數的請求路徑了
String queryString = request.getQueryString();String fullPath = url + queryString; // 或者是url_buffer.toString()+queryString;