而且好像在jb里面参数的传递不会乱码 但是在IE里面就会有这个问题
高手帮忙啊..
高手帮忙啊..
解决方案 »
- 急急急啊!!
- struts2中,如何将方法封装!struts2中的方法可以接受参数吗?
- mule axis 发布webservice后,如何获取客户端ip
- spring 事务回滚问题
- org.springframework.web.context.ContextLoaderListener 在哪个jar里面呀
- java 代码 在获取当前的时间 加十年
- 如何发UDP包?
- 谁发给我一个用eclipse+tomcat开发的jsp:usebean的小小的例子,170就是你的了。(学习jsp:usebean的用法)
- 建连接池失败 怎么搞啊?
- 泣求《J2EE 编程指南(1.3版)》源代码
- 教代码提示的错误码
- 求Eclipse使用指南!!
//***************************************************
//名称:ChangeCode
//功能:转换指定字符串的字符集(字符编码)
//输入:strSource: 要转换的字符串; strCodeFrom: 源字符集; strCodeTo: 目的字符集
//输出:
//返回:转换之后的字符串
//***************************************************
public static String ChangeCode(
String strSource,
String strCodeFrom,
String strCodeTo)
{
byte[] baTemp = null;
try
{
baTemp = strSource.getBytes(strCodeFrom);
strSource = new String(baTemp, strCodeTo);
}
catch (Exception e)
{
return (e.toString());
} return (strSource);
}
if (orign != null) {
try {
orign = new String(orign.getBytes("ISO8859-1"),"GBK"); }
catch (Exception ex) {
System.out.println("toChinese exception:" + ex.getMessage());
System.out.println("The String is:" + orign);
}
}
System.out.println("orign"+orign);
return orign;
}
我也用这个进行转换了可是还是乱码阿。
public class MyActionServlet extends ActionServlet {
public MyActionServlet() {
}
protected void process(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException {
request.setCharacterEncoding("GBK");
super.process(request, response);
}}
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>hrbjs.util.MyActionServlet</servlet-class>
这是在网上找的servlet的设置 我也作了
但是现在是有的页面可以正常显示 有的步行..
不知道为什么
import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.FilterChain;
import java.io.IOException;public class SetCharacterEncodingFilter
implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true; public SetCharacterEncodingFilter() {
} 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 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);
// response.setContentType("text/html;charset=" + encoding);
}
} chain.doFilter(request, response); } public void destroy() {
this.encoding = null;
this.filterConfig = null; } protected String selectEncoding(ServletRequest request) { return (this.encoding); }}
然后在web.xml进行了配置