1. 程式人生 > >requesth獲取參數

requesth獲取參數

用戶 name adl readline nts .get int names 參數名稱

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setCharacterEncoding("utf-8");
String token ;
token=request.getHeader("token");
System.out.println("當前用戶請求頭為:"+token);

String requestURI = request.getRequestURI();
Enumeration<String> em = request.getParameterNames();


System.out.println("current request meth:"+requestURI);
boolean b = em.hasMoreElements();
if(b){
String name = em.nextElement();
String value = request.getParameter(name);
System.out.println("form表單請求的參數名稱:"+name+"請求的參數值:"+value);
}


BufferedReader br = request.getReader();

String str, wholeStr = "";
while((str = br.readLine()) != null){
wholeStr += str;
}
System.out.println("body--Json中請求的參數名稱:"+wholeStr);

}

requesth獲取參數