GET重定向url带特殊字符参数拼接问题的解决
2017-05-26 17:07
465 查看
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
StringBuffer sb = new StringBuffer();
String valueurl = null;
Map<String, String[]> map = request.getParameterMap();
for (Entry<String, String[]> str : map.entrySet()) {
String[] value = str.getValue();
StringBuffer values = new StringBuffer();
for (int i = 0; i < value.length; i++) {
values.append(value[i]);
}
if ("url".equals(str.getKey())) {
valueurl = values.toString();
continue;
} else {
sb.append("&" + str.getKey() + "=" + values);
}
}
String url = valueurl + sb.toString();
System.out.println(url);
String tbName = Const.getPropertyByName("conf", "TBNAME");
String addr = request.getRemoteAddr();
System.out.println(addr);
response.sendRedirect(url);
try {
String sql = "insert into " + tbName + " (count,ip_addr,url) values (?,?,?)";
PreparedStatement pst = DB.getConn().prepareStatement(sql);
pst.setInt(1, count);
pst.setString(2, addr);
pst.setString(3, url);
pst.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
count++;
}
response.setContentType("text/html;charset=UTF-8");
StringBuffer sb = new StringBuffer();
String valueurl = null;
Map<String, String[]> map = request.getParameterMap();
for (Entry<String, String[]> str : map.entrySet()) {
String[] value = str.getValue();
StringBuffer values = new StringBuffer();
for (int i = 0; i < value.length; i++) {
values.append(value[i]);
}
if ("url".equals(str.getKey())) {
valueurl = values.toString();
continue;
} else {
sb.append("&" + str.getKey() + "=" + values);
}
}
String url = valueurl + sb.toString();
System.out.println(url);
String tbName = Const.getPropertyByName("conf", "TBNAME");
String addr = request.getRemoteAddr();
System.out.println(addr);
response.sendRedirect(url);
try {
String sql = "insert into " + tbName + " (count,ip_addr,url) values (?,?,?)";
PreparedStatement pst = DB.getConn().prepareStatement(sql);
pst.setInt(1, count);
pst.setString(2, addr);
pst.setString(3, url);
pst.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
count++;
}
相关文章推荐
- 【已解决】GET方法的参数中处理URL特殊字符&%等
- url 传递参数(特殊字符)解决方法
- 静态页面如何接收参数以及解决特殊字符的编码问题
- 解决get方法传递URL参数中文乱码问题
- url 传递参数(特殊字符)解决方法
- android客户端通过Get方式提交参数给服务器,使用URL和HttpURLConnection实现,以及乱码问题解决
- 【.Net】关于URL传值多个参数以及特殊字符的问题
- 解决get方法传递URL参数中文乱码问题
- JavaScript中url 传递参数(特殊字符)解决方法
- url 传递参数(特殊字符)解决方法
- url 特殊字符 传递参数解决方法
- url参数中有+、空格、=、%、&、#等特殊符号的问题解决
- url参数中有+、空格、=、%、&、#等特殊符号的问题解决
- url 特殊字符 传递参数解决方法
- url 特殊字符 传递参数解决方法
- url 传递参数(特殊字符)解决方法
- js的form表单提交url传参数(包含+等特殊字符)的解决方法
- url 传递参数(特殊字符)解决方法
- URL的参数中有加号传值的问题(URL特殊字符)
- URL编码----url参数中有+、空格、=、%、&、#等特殊符号的问题解决