日期:2014-05-18  浏览次数:20640 次

JSP编码问题!实在没办法了!!!!
<%@   page   contentType= "text/html;charset=GB2312 "   pageEncoding= "GBK "%>  
<html>  
<head>  
</head>  
<body>  
<form   method= "post "   action= "session2.jsp "   >  
请输入姓名 <input   type= "text "   name= "username ">  
<input   type= "submit "   value= "submit ">  
</form>  
</body>  
</html>  


页面二:  


<%@   page   contentType= "text/html;charset=GB2312 "   pageEncoding= "GBK "   %>  
<html>  
<head>  
</head>  
<body>  
<%@   page   language= "java "   %>  
<%!   String   name= " ";   %>  
<p>  
<%  
name=request.getParameter( "username ");  
session.putValue( "username ",name);  

%>  
您的姓名是: <%=name   %>  
<form   method= "post "   action= "session3.jsp ">  
您最喜欢的水果: <input   type= "text "   name= "fruit ">  
<input   type= "submit "   name= "submit ">  
</form>  
</body>  
</html>  


英文没问题!   中文一旦输入就是出现问号之类的乱码   困扰好久了!  

页面三:  

<%@   page   language= "java "   import= "java.util.* "   pageEncoding= "GBK "%>  
<%@   page   contentType= "text/html;charset=GB2312 "   %>  
<%  
String   path   =   request.getContextPath();  
String   basePath   =   request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";  
%>  

<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">  
<html>  
<head>  
<base   href= " <%=basePath%> ">  

<title> My   JSP   'session3.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>  
<%  
String   fruit=request.getParameter( "fruit ");  
session.putValue( "fruit ", "name ");  
String   a=(String)session.getValue( "username ");