游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1553|回复: 2

JAVA??????????? wxh

[复制链接]

1367

主题

1993

帖子

2118

积分

金牌会员

Rank: 6Rank: 6

积分
2118
发表于 2004-9-21 19:43:00 | 显示全部楼层 |阅读模式
???????JAVA?????????

1??jsp??????<%@page contentType=text/html;charset=GB2312%>
?servlet???httpServlerResponse.setContentTpye(text/html; charset=GB2312);??????????

2???JDBC??mysql???????????????????????????
jdbc://mysql://hostname:port/DBname?user=username&password=pwd&
useUnicode=true&characterEncoding= iso-8859-1
????????????????????????
<parameter>
<name>url</name>
<value>jdbc:mysql://hostname:port/DBname? &useUnicode=true&characterEncoding=iso-8859-1</value>
</parameter>
?????&??&?????XML????????????

3?????????????????????????????????
String desc = rs.getString(desc);
desc = new String(desc.getBytes(ISO-8859-1)?GB2312);

4????????????Servlet?Servlet??????????????????????
??????servlet?????????????
httpServlerRequest.setCharacterEncoding(GB2312);

5. ?struts??????????????JDK????????
>native2ascii -encoding BG2312 Myresource.properties Myresource_zh.properties

6??struts???org.apache.struts.action.RequestProcessor????????processPreprocess()??:
package com.mypro.action;

public class MyProRequestProcessor extends RequestProcessor
{
protected boolean processPreprocess (HttpServletRequest request,
HttpServletResponse response)
{
try
{
request.setCharacterEncoding(GB2312);
//other code
}
catch(Exception e){}

return true;
}
}
???????????struts-config.xml?
<controller processorClass= com.mypro.action.MyProRequestProcessor/>

7. ?filter??????
package com.kefeiannan;

import java.io.IOException;
import javax.servlet.*;

public class SetCharacterEncodingFilter implements Filter
{

protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;

public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {

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;
}
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}
???????web.xml,?<web-app>????
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.kefeiannan.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
[em3] [em18]

109

主题

1451

帖子

1475

积分

金牌会员

??

Rank: 6Rank: 6

积分
1475
发表于 2004-9-25 00:04:00 | 显示全部楼层

Re: JAVA??????????? wxh

[em16]Well,It's a good classic article?Moderator. [em10]

29

主题

421

帖子

436

积分

中级会员

Rank: 3Rank: 3

积分
436
发表于 2004-10-6 23:13:00 | 显示全部楼层

Re: JAVA??????????? wxh

jsp??????????????
?????????????utf-8???????
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-8-18 22:04

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表