package com.digfa;public class Util
{
public static String codeString(String s)
{ String str=s;
try{byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e)
{ return str;
}
}
}
{
public static String codeString(String s)
{ String str=s;
try{byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e)
{ return str;
}
}
}
解决方案 »
- ssh中如何在上传的图片上生产水印
- 菜鸟求知道第三弹 session的使用的问题
- 为什么我的web.xml 中的 listener 初始化两次
- 十分紧急 一个简单的数学公式 正则表达式 写法
- 大家讨论下 jdk/bin 中的那些执行文件各有什么功能 如:javap ,javaw, javadoc 。。。。
- 访问jsp页面,访问到文件夹的时候,怎么让它不显示文件夹里文件列表?
- 疯了~!~!
- HttpClient 如何模拟登录网站,网站中有验证Cache的
- hibernate自身一对多的问题,求解
- URLConnection的编码问题!!
- 顶者有分!急!莫名其妙的问题:rs.getString("xxx")有时不能读取完整数据!
- 这样一个留言板个人做大概要多久 大概什么价格呢??
lijunjiejava(不眠之夜):我这个函数要在formbean中调用的,好像不能在formbean中request.setCharacterEncoding("gb2312")吧
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>SHIFT_JIS</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>注意:要加在<listener>前面、<context-param>后面。
.对了,在jsp中直接设置传入得参数为汉字怎么设置
比如<form name="replyform" method="post" action="replyAction.do?title=手机测试">
如何设置可以是的title传入后就是汉字,不需要进行转化
我用的试tomcat,我按照你得方法做了,但是:(PS :我目前在Jbuilder9下面调试)
Exception starting filter Set Character Encoding: java.lang.ClassNotFoundException: filters.SetCharacterEncodingFilter
String str = "error" ;
try{
str=new String(URLDecoder.decode(s).getBytes("ISO-8859-1"), "gb2312"));
return str;
}
catch(Exception e){
return str;
}
}
import java.io.*;public abstract class SetCharacterEncodingFilter implements Filter{
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destory(){
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;
}
}
public String selectEncoding(ServletRequest request){
return this.encoding;
}
}有一点要注意,我那个SHIFT_JIS是日文编码。
你要是用中文改成GB2312或者ISO8859_1就行了