request 解决中文乱码问题
2014-08-15 10:46
176 查看
package request;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RequestDemo4 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//表单页面数据以什么吗表发过来,就控制request以什么吗表来读
//解决post提交的中文乱码
request.setCharacterEncoding("UTF-8");//只对post提交有效
System.out.println(request.getParameter("username"));
//get方式提交的数据,解决乱码问题
//由于request.setCharacterEncoding("UTF-8")只对post方式提交的数据有效
//所以这里get方式提交的数据只能手动解决
//request默认使用的是iso8859编码,我们查传过来的数据在iso8859里面对应的编码,再那对应的值去utf-8吗表里查对应的值
String name = request.getParameter("username");
//解决get提交的中文乱码《也适用于超链接提交过来的数据-------超链接提交的额数据是以get方式提交的》
name = new String(name.getBytes("iso8859-1"),"UTF-8");
System.out.println(name);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RequestDemo4 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//表单页面数据以什么吗表发过来,就控制request以什么吗表来读
//解决post提交的中文乱码
request.setCharacterEncoding("UTF-8");//只对post提交有效
System.out.println(request.getParameter("username"));
//get方式提交的数据,解决乱码问题
//由于request.setCharacterEncoding("UTF-8")只对post方式提交的数据有效
//所以这里get方式提交的数据只能手动解决
//request默认使用的是iso8859编码,我们查传过来的数据在iso8859里面对应的编码,再那对应的值去utf-8吗表里查对应的值
String name = request.getParameter("username");
//解决get提交的中文乱码《也适用于超链接提交过来的数据-------超链接提交的额数据是以get方式提交的》
name = new String(name.getBytes("iso8859-1"),"UTF-8");
System.out.println(name);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
相关文章推荐
- 使用filter解决request.getParameter的中文乱码问题
- request传中文值出现乱码问题的解决方法
- JSP用过滤器解决request getParameter中文乱码问题
- request、response 中文乱码问题与解决方式
- request、response 中文乱码问题与解决方式
- 完美解决由NSURLConnection或者ASIHttpRequest返回的中文乱码问题。
- 解决XMLHttpRequest中文乱码问题
- request、response 中文乱码问题与解决方式
- request、response 中文乱码问题与解决方式
- 解决request中文乱码的问题
- XMLHttpRequest进行ajax通讯时中文乱码问题解决
- 解决request.getParameter()中文乱码的问题
- 如何解决Request.Uri.ToString() 中文乱码的问题...
- JSP用过滤器解决request getParameter中文乱码问题
- 解决request中文乱码的问题
- json传递中文乱码解决方法以及解决request.getParameter()获取参数为乱码的问题
- 通过过滤器(Filter)解决JSP的Post和Request中文乱码问题
- jsp中request.getParameter()中文乱码问题解决
- HttpServletRequest解决中文乱码的问题
- Request.Querystring中文乱码问题解决