当前位置: 代码迷 >> Java Web开发 >> 为何一直出现乱码呢,求解,该怎么解决
  详细解决方案

为何一直出现乱码呢,求解,该怎么解决

热度:138   发布时间:2016-04-17 00:13:03.0
为何一直出现乱码呢,啊~~~~~`求解
Java code
<%@ page contentType="text/html;Charset=GB2312" %><HTML><BODY bgcolor=cyan>   <FORM action="showMessage1.jsp" method=post name=form>       <INPUT type="text" name="boy">        <INPUT TYPE="submit" value="提交给showMessage1.jsp" name="submit">   </FORM> </BODY></HTML>


Java code
<%@ page contentType="text/html;Charset=GB2312" %><MHML><BODY>   <P>获取文本框提交的信息:   <%  String textContent=request.getParameter("boy");   %><BR>   <%=textContent%> <P> 获取按钮的名字:   <%  String buttonName=request.getParameter("submit");   %><BR>  <%=buttonName%> </BODY></HTML>


------解决方案--------------------
加个pageEncoding='GB2312'试试
------解决方案--------------------
写个过滤器,拦截所有请求并转码
------解决方案--------------------
1.<%@ page contentType="text/html;Charset=GB2312" %>修改为<%@ page contentType="text/html;charset=GB2312" %> 解决页面显示乱码
2.接收时要转码
<%@ page contentType="text/html;charset=GB2312"%>
<MHML><BODY>
<P>获取文本框提交的信息:
<% String textContent=new String(request.getParameter("boy").getBytes("iso-8859-1"),"GB2312");
%>
<BR>
<%=textContent%> 
<P> 获取按钮的名字:
<% String buttonName=new String(request.getParameter("submit").getBytes("iso-8859-1"),"GB2312");
%>
<BR> <%=buttonName%> 
</BODY></HTML>

------解决方案--------------------
设置下编码格式request.setCharacterEncoding("gb2312")如果还不行的话,就这样转换
String textContent=request.getParameter("boy");
textContent=new String(textContent.getBytes("ISO-8859-1"),"gb2312")

String buttonName=request.getParameter("submit");
buttonName=new String(buttonName.getBytes("ISO-8859-1"),"gb2312")
------解决方案--------------------
你把中间件也设为GB2312即可。
------解决方案--------------------
java获取时加入下面语句:
request.setCharacterEncoding("utf-8");
------解决方案--------------------
request.setCharacterEncoding("gb2312")
------解决方案--------------------

JScript code
String    boy= new String(request.getParameter("boy").trim().getBytes("8859_1"));String    submits= new String(request.getParameter("submit").trim().getBytes("8859_1"));
------解决方案--------------------
要是使用myeclips需要在选项里面配置,code改为GBK试一下,因为你可能是从别的地方黏贴的代码到myeclips当中的
------解决方案--------------------
可以修改tomcat的配置文件sever.xml 
<Connector port="8080" protocol="HTTP/1.1" 
connectionTimeout="20000" 
redirectPort="8443" />
加一句:Encoding="utf-8"
  相关解决方案