又见jap中文乱码错误!!晕
又见jap中文乱码错误!!晕
我是查了许多文件,也用了许多办法,他还是乱码!!
也用了这个类,
public abstract class Convert {
// 把ISO-8859-1码转换成GB2312
public static String ISOtoGB(String iso){
String gb;
try{
if(iso.equals( " ")||iso==null){
return " ";
}else{
iso = iso.trim();
gb = new String(iso.getBytes( "ISO-8859-1 "), "GB2312 ");
return gb;
}
}
catch(Exception e){
System.err.print( "编码转换错误:\n "+e.getMessage());
return " ";
}
}
}
*.jsp
<%
......
response.setCharacterEncoding( "gb2312 ");
连pirateSex2=Convert.ISOtoGB( "女 ");/或pirateSex2= "女 ";
response.sendRedirect( "/MyOne_Piece/index.jsp?pirateSex= "+pirateSex2);
......
%>
//index.jsp。。。
<%@ page contentType= "text/html; charset=gb2312 " %〉
<%
response.setCharacterEncoding( "gb2312 "); //--〉
request.setCharacterEncoding( "gb2312 "); //**写一个不对我写了俩
String pirateSex=request.getParameter( "pirateSex ");
pirateSex=Convert.ISOtoGB(pirateSex); ////////====loop===///////**
%>
<head>
...
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
...
</haed>
<html>
...
<p> <%=pirateSex%> </p>
...
</html>
这么写了还乱码
网上说有的也得配Tomcat的。
还有String title=new String(request.getParameter( "title ").getBytes( "ISO8859_1 "), "gb2312 "); 这一句如果要写在上面“////////====loop===///////”
这一行的位置连运行都不行
description The server encountered an internal error () that prevented it from fulfilling this request.
//////////////////这个错误/////////////////////
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
。。。。。。。
//////////////////////////////////////////////
还有我也在每个JSP 的属性里选择了gb2312好像
String pirateSex2= "女 ";的时候pirateSex2里就已经乱码了。
晕死了,大家帮帮我吧 !!!
[解决办法]
加这个类:
package org.battwofame.hellojava.telservlet.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterEncodingFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding( "gbk ");
chain.doFilter(request, response);
}
public void init(FilterConfig arg0) throws ServletException {
}
}
在web.xml的最上面加:
<filter>
<filter-name> CharacterEncodingFilter </filter-name>
<filter-class> org.battwofame.hellojava.telservlet.filter.CharacterEncodingFilter </filter-class>
</filter>
<filter-mapping>
<filter-name> CharacterEncodingFilter </filter-name>
<url-pattern> /* </url-pattern>
</filter-mapping>
你只要直接把这考过去,换个包名就可以用
[解决办法]
加这个类实实阿!
乱码 在MYSQL的目录下面
//////////////////////////////////码转换类//////////////////////////////////
package myonepiece;
public abstract class Convert {
/**
* 把ISO-8859-1码转换成GB2312 //接收数据
*/
public static String ISOtoGB(String iso){
String gb;
try{
if(iso.equals( " ")||iso==null){
return " ";
}else{
iso = iso.trim();
gb = new String(iso.getBytes( "ISO-8859-1 "), "GB2312 ");
return gb;
}
}
catch(Exception e){
System.err.print( "编码转换错误:\n "+e.getMessage());
return " ";
}
}
/**
* 把GB2312码转换成 ISO-8859-1//提交数据用
*/
public static String gBtoISO(String gb){
String iso;
try{
if(gb.equals( " ")||gb==null){
return " ";
}else{
gb = gb.trim();
iso = new String(gb.getBytes( "GB2312 "), "ISO-8859-1 ");
return iso;
}
}
catch(Exception e){
System.err.print( "编码转换错误:\n "+e.getMessage());
return " ";
}
}
}
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html