解决apache Web服务器网页乱码
两种方法都可以解决apache Web办事器网页显示乱码的不懂的题目。 其中以第二种方法最好最简单,且一劳永逸。
我用的Redhat Linux 8.0 自带的Apache 2.0
(1)办事器端:
修改httpd.conf (在Redhat中放置的位置为/etc/httpd/conf/)
查找:
AddDefaultCharset ISO-8859-1
改为:
代码:
#AddDefaultCharset ISO-8859-1
AddDefaultCharset off
这种体式格局关掉了办事器的默认语言的发送,这样仅凭html。多是Tomcat在接收到哀求后,并没有能够根据request中的信息提早正确的编码体式格局。
解决:可以添加一个设置字符集的Filter。
代码:
package filters;
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
代码:
public class GetFormData extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
String paramValues;
paramValues=request.getParameter("UserName";
response.setContentType("text/html;charset=gb2312" ;
PrintWriter out=response.getWriter();
out.println("test";
out.println("以下是收到的数值
";
out.println("UserName=" paramValues);
out.println("
接收结束";
out.println("";
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
doGet(request,response);
}
}
由于操作系统、浏览器、数值库、JVM采用的字符集都不一样,基于Weblogic Server开发的应用经常出现中文显示乱码不懂的题目,其实在Weblogic Server上运行的WEB应用有许多与字符集有关的设置,底下做一个总结,为了正确处理中文,最好把这些个设置都设上。
1. 在JSP文件头加入
代码:
指定该JSP采用的字符集。
2.在Weblogic.xml文件的中加入:
援用:
encoding
GBK
指定JSP文件中采用的字符集,在JSP文件中的会覆盖该设置
3.在Weblogic.xml文件的中加入
代码:
compilerSupportsEncoding
true
要是为TRUE,指定在编译JSP文件时,采用在JSP文件中定义的
或者中定义的encoding参数中定义的字符集进行编码,要是为FALSE,则采用JVM中默认指定的字符集进行编码。
4. Weblogic Server需要把HTTP request(GET 和POST)中的数值从它的原始编码转化为Unicode,以便Java servlet API进行处理,为了做这种转换,Weblogic Server需要懂得HPPT request中的数值的编码体式格局。这可以通过在Weblogic.xml的中设置.
代码:
〈INPUT-charset>
/
GBK
5.从ORACLE数值库中检索出来的中文显示不正确时,在这种环境下,要是数值库使用的是中文字符集,并使用的是Type 2 JDBC Driver时,可加入Weblogic.codeset=GBK的属性来解决这个不懂的题目。代码如下:
代码:
java.util.Properties props = new java.util.Properties();
props.put(Weblogic.codeset, GBK);
props.put(user, scott);
props.put(password, tiger);
String connectUrl = jdbc:Weblogicracle;
Driver myDriver = (Driver)
Class.forName(Weblogic.jdbc.oci.Driver).newInstanc e();
Connection conn =
myDriver.connect(connectUrl, props);
6. 要是是采用WTC调用Tuxedo中的办事,在JSP页面中无法正确显示中文,必需使安装Tuxedo的办事器上的NLS_LANG环境变量与数值库中的字符集的设置一样。如后台Oracle数值库中的字符集设置为 SIMPLIFIED CHINESE_CHINA.ZHS16GBK,那么Tuxedo应用办事器上的NLS_LANG环境变量应设置为:
代码:
export NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
- 上一篇:php获取当前时间错误,有时差怎么解决
- 下一篇:没有了

QQ客服在线