request得到带参数的请求url
//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 url = request.getRequestURI();
//The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters
//eg. http://127.0.0.1:8080/manage/editExam.domethod=goExamSet&type=U
StringBuffer url_buffer = request.getRequestURL();
StringBuffer url_buffer = request.getRequestURL();
HttpServletRequest 的这两种方法都只能得到不包含参数的请求url,区别如下:
1 前者返回相对路径,后者返回完整路径
2 前者返回string ,后者返回stringbuffer
要想得到完整请求url可以通过如下方法,getQueryString()得到的是url后面的参数串,和前者相加就是带参数的请求路径了
String queryString = request.getQueryString();
String fullPath = url + "?" +queryString; // 或者是url_buffer.toString()+queryString;
String fullPath = url + "?" +queryString; // 或者是url_buffer.toString()+queryString;
原文:http://blog.csdn.net/lovelyhermione/article/details/2293467