我做了个网站 主页用<%@ include file="xxx.jsp"%>这样的方式 调用了 几个网页!
在主页里 设置了<%@ page contentType="text/html; charset=gb2312"%>
其他 调用的页的字体都变成了 乱码 如果在 调用的页里加<%@ page contentType="text/html; charset=gb2312"%> 话出现冲突! 我该怎么办了??
请大家 帮帮忙!
在主页里 设置了<%@ page contentType="text/html; charset=gb2312"%>
其他 调用的页的字体都变成了 乱码 如果在 调用的页里加<%@ page contentType="text/html; charset=gb2312"%> 话出现冲突! 我该怎么办了??
请大家 帮帮忙!
public String codeToString(String str)
{
String str1=str;
try{
byte b[]=new byte[1024];
b=str1.getBytes("ISO-8859-1");
str1=new String(b);
return str1;
}
catch(Exception e)
{return str1;
}}
你只要能调用这个函数codetoString(request.getparameter("你的内容"));
public String codtoString(String str)
{
String str1=str;
try{
byte b[]=new byte[1024];
b=str1.getBytes("ISO-8859-1");
str1=new String(b);
}catch(Exception e)
{
e.printStackTrace();
return str1;
}
return str1; }
哪个页里面都没加 <%@ page contentType="text/html; charset=gb2312"%>
在主页里,右键->编码->简体中文(GB2312) 出现中文
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class SetCharacterEncodingFilter extends HttpServlet implements Filter {
private FilterConfig filterConfig; //Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
} //Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws IOException,ServletException {
request.setCharacterEncoding("GB2312");
filterChain.doFilter(request,response);
} //Clean up resources
public void destroy() {
}
}