package com;public class ToUtil {
public ToUtil() {
}
public static String Togb2312(String str)
{
byte gb2312[]=new byte[str.length()];
for(int i=0;i<str.length();i++)
{
gb2312[i]=(byte)str.charAt(i);
}
return new String(gb2312);
}
}一个转化函数!
public ToUtil() {
}
public static String Togb2312(String str)
{
byte gb2312[]=new byte[str.length()];
for(int i=0;i<str.length();i++)
{
gb2312[i]=(byte)str.charAt(i);
}
return new String(gb2312);
}
}一个转化函数!
解决方案 »
- Struts select 标签 异常
- 上传文件同时得到描述
- 怎样用JAVA程序连接需要客户端证书认证的SSL WEB网站
- 为什么没人讨论下阿里巴巴的搜索。好像用LUCENE根本做不出来。很神秘。
- 再问用jsp如何实现你收到的留言是否读过,像收到的邮件一样?
- 我有一个过滤器,过滤某个文件夹下面的所有文件,但如果用struts,它不能过滤.do的action阿,有没什么标准方法做到呢?
- 在SSH框架中 关于HQL的子查询
- 谁能解释一下这段代码?
- 我使用jspsmartupload时对中文文件的下载有问题,急!!
- 很简单的两个问题!请高手指点
- 请问可不可以用一个SQL语句(在程序中)把一些数据从一个数据库中拷贝到另一个数据库中呢?
- 查库乱码问题?
request.setCharacterEncoding("GB2312");应该就可以了
<%@ page contentType="text/html;charset=GBK" %>
<%request.setCharacterEncoding("GBK");%>
特别表现在include的页面上,没有办法解决,除非你买个正版的用。
用 asdlcj(asdlcj) 贴出来的 togb2312 函数转换一下就可以了 public static String toGB2312(String str) {
int len = str.length();
if (len != 0) {
byte[] GB2312 = new byte[len];
for (int i = 0; i < len; i++) {
GB2312[i] = (byte) str.charAt(i);
}
return new String(GB2312);
}
return "";
}
然后调用格式为:
String str = toGB2312(rs.getString("param"));
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class EncodingServlet extends HttpServlet implements Filter {
private FilterConfig filterConfig;
private String targetEncoding="gb2312";
//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
this.targetEncoding = filterConfig.getInitParameter("encoding");
}
//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
try {
HttpServletRequest srequest = (HttpServletRequest)request;
srequest.setCharacterEncoding(targetEncoding);
filterChain.doFilter(request, response);
}
catch(ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
}
catch(IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}
//Clean up resources
public void destroy() {
this.filterConfig = null;
}
}