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

jsp页面传值问题
createInventory.jsp页面:
<%@page   contentType= "text/html "   pageEncoding= "UTF-8 "%>
<html>
<script   language= "javascript ">

function   selectInvC()   {
      var   cInvCName=document.cInvCName.value;
      var   a   =   window.open( "showInventoryClass.jsp?cInvCName= "+cInvCName+ " ", "ppp ", "top=100,left=150,   width=600,height=400,toolbar=no   ,scrollbars=yes ");
}

</script>

<input   type= "text "   name= "cInvCName "   value= " "   >  
<IMG     src= "../images/select.gif "   style= "cursor:hand "   onclick= "return   selectUnit() "/>    
</html>

showInventoryClass.jsp页面:
<%@page   contentType= "text/html "   pageEncoding= "UTF-8 "%>
<html>
<%
      String   cInvCName=request.getParameter( "cInvCName ");
%>
</html>

问题:
当createInventory.jsp页面中cInvName的值是一个汉字时,   比如   “糖”,那么在showInventoryClass.jsp中request.getParameter( "cInvCName ")   得到的是乱码。但如果是两个汉字,比如“白糖”,得到的却是正常的值。如果是三个字的话,前两个字是正常的,最后一个字是乱码。请问:这是怎么一回事?
IDE:netbeans5.5     jdk:1.5       tomcat:5.5.17

------解决方案--------------------
在你取出该值之前,设一下编码规则:request.setCharacterEncoding( "gb2312 ");
应该是可以的