JSP乱码另解

<span style="font-size:24px;"><strong>JSP中:解决方法另解
</strong></span>


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	   request.setCharacterEncoding("utf-8");
	String name = request.getParameter("name");
	String pwd = request.getParameter("pwd");
	


	if ("我们".equals(name) && "admin".equals(pwd)) {

	String n=new String(request.getParameter("name").getBytes("UTF-8"),"ISO-8859-1");

	 response.sendRedirect("admin.jsp?name="+n); 
	}else{
	String n=new String(request.getParameter("name").getBytes("UTF-8"),"ISO-8859-1");
	 response.sendRedirect("normal.jsp?name="+n); 
	} 
%>






 

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%

String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
	
 %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'admin.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <p>您好 , 您是管理员:<%=name%>欢迎进入本来页面</p>
  </body>
<html>


 


 无论是post还是get方法提交的时候解决方法:在发送之前将UTF-8转码成ISO-8859-1发送

String n=new String(request.getParameter("name").getBytes("UTF-8"),"ISO-8859-1");

在接收界面在再将ISO--8859-1转码成UTF-8显示

如果post不通过ISO-8859-1传送数据过去,在接收界面是接收不到中文,


 

你可能感兴趣的:(JSP乱码另解)