首页 > 代码库 > Java文字乱码问题及页面转发

Java文字乱码问题及页面转发

1.请求文字编码格式

1  request.setCharacterEncoding("UTF-8");

2.响应文字编码格式

1   response.setCharacterEncoding("utf-8");

3.响应内容文件格式

1   response.setContentType("text/html");

 

1  PrintWriter out = response.getWriter();  

4.根据底层编码格式转换字符类型

1 String str = request.getParameter("name");2 String name = new String(str.getBytes("ISO-8859-1"),"utf-8");

 

弹框

1 out.println("<script>");2 out.println("alert(‘用户名或密码错误!‘);");3 out.println("location=‘" + request.getContextPath() + "/page/Login.jsp‘");4 out.println("</script>");

 

页面转发

1 request.getRequestDispatcher("page/LoginSuccess.jsp").forward(request, response);

页面重定向

1 response.sendRedirect("page/LoginSuccess.jsp");

 


 

Java文字乱码问题及页面转发