如何獲取到get丶post 請求的url裡的所有引數
阿新 • • 發佈:2019-01-30
public class GetParams extends HttpServlet {
private static final long serialVersionUID = 1L;
public GetParams() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
writer.println("GET " + request.getRequestURL() + " "
+ request.getQueryString());
Map<String, String[]> params = request.getParameterMap();
String queryString = "";
for (String key : params.keySet()) {
String[] values = params.get(key);
for (int i = 0; i < values.length; i++) {
String value = values[i];
queryString += key + "=" + value + "&";
}
}
// 去掉最後一個空格
queryString = queryString.substring(0, queryString.length() - 1);
writer.println("GET " + request.getRequestURL() + " " + queryString);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
Map<String, String[]> params = request.getParameterMap();
String queryString = "";
for (String key : params.keySet()) {
String[] values = params.get(key);
for (int i = 0; i < values.length; i++) {
String value = values[i];
queryString += key + "=" + value + "&";
}
}
// 去掉最後一個空格
queryString = queryString.substring(0, queryString.length() - 1);
writer.println("POST " + request.getRequestURL() + " " + queryString);
}
}
private static final long serialVersionUID = 1L;
public GetParams() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
writer.println("GET " + request.getRequestURL() + " "
+ request.getQueryString());
Map<String, String[]> params = request.getParameterMap();
String queryString = "";
for (String key : params.keySet()) {
String[] values = params.get(key);
for (int i = 0; i < values.length; i++) {
String value = values[i];
queryString += key + "=" + value + "&";
}
}
// 去掉最後一個空格
queryString = queryString.substring(0, queryString.length() - 1);
writer.println("GET " + request.getRequestURL() + " " + queryString);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
Map<String, String[]> params = request.getParameterMap();
String queryString = "";
for (String key : params.keySet()) {
String[] values = params.get(key);
for (int i = 0; i < values.length; i++) {
String value = values[i];
queryString += key + "=" + value + "&";
}
}
// 去掉最後一個空格
queryString = queryString.substring(0, queryString.length() - 1);
writer.println("POST " + request.getRequestURL() + " " + queryString);
}
}