如何解决javarequest请求中有多个参数的问题
推荐于2017-12-16 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517195
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
通过程序遍历http请求的所有参数放到hashmap中,用的时候方便了。
如果参数值有中文,那么需要在程序中添加filter转码,或者在下面程序里,对paramValue转码
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Map map = new HashMap();
Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() != 0) {
System.out.println("参数:" + paramName + "=" + paramValue);
map.put(paramName, paramValue);
}
}
}
Map map = new HashMap();
Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() != 0) {
System.out.println("参数:" + paramName + "=" + paramValue);
map.put(paramName, paramValue);
}
}
}
}
如果参数值有中文,那么需要在程序中添加filter转码,或者在下面程序里,对paramValue转码
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Map map = new HashMap();
Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() != 0) {
System.out.println("参数:" + paramName + "=" + paramValue);
map.put(paramName, paramValue);
}
}
}
Map map = new HashMap();
Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() != 0) {
System.out.println("参数:" + paramName + "=" + paramValue);
map.put(paramName, paramValue);
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询