编码出错(无法显示中文)

阅读更多

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>




ward test


<%
//response.setCharacterEncoding("utf-8");
System.out.println("--------------ward Test-----------------------");
System.out.println("Forward Test 1");

 %>

	


 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>     to ward   <% //request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); System.out.println("---------------For ward Test-----------------------"); String user=request.getParameter("user"); if(user==null){ user="null"; } System.out.println(user); %> 

用户名

<%= user %>

两个JSP页面跳转后无法取得user值总结如下:

 

场合:页面本身有中文的时候

解决方法:servlet:response.setContentType("text/html;charset=utf-8");

                 JSP:<%@page contentType="text/html;charset=utf-8"%>

注意:一定要写在PrintWriter out=rsesponse.getWriter();之前

场合:解决get方式乱码问题:

解决方法:修改server.xml-->               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="utf-8"/>

场合:解决post方式提交内容的乱码问题:

解决方法:request.setCharacterEncoding("utf-8");

注意:一定要写在存取第一个参数之前

          不要调用response.setCharacterEncoding("utf-8");

场合:url地址包含中文参数:

解决方法:<% request.setCharacterEncoding("utf-8");%>

 

你可能感兴趣的:(编码出错(无法显示中文))