各位大哥,请问怎样才能正确读取access中的中文啊,存在access中的数据能正确显示中文,但读取时出现乱码,请问如何解决?谢谢。
下面是小弟的解决办法,但是仍然是乱码。<%!
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("GBK");
String temp=new String(temp_t,"ISO8859_1");
return temp;
}
catch(Exception e)
{
}
return "null";
}
%> <td>"+getStr(RSa.getString("realname"))+"</td>
下面是小弟的解决办法,但是仍然是乱码。<%!
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("GBK");
String temp=new String(temp_t,"ISO8859_1");
return temp;
}
catch(Exception e)
{
}
return "null";
}
%> <td>"+getStr(RSa.getString("realname"))+"</td>
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import java.io.IOException;/**
*
* Date: 2005-9-19
* Time: 17:33:36
* @author Duzk
*/
public class MyFilter extends HttpServlet implements Filter {
private FilterConfig filterConfig;
//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) {try {
request.setCharacterEncoding("GBK");
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() {
}
}然后在web.xml里加上这段
<filter>
<filter-name>MyFilter</filter-name>
<filter-class>类路径.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<%
request.setCharacterEncoding("gb2312");
%>
就可以了!基本上能解决数据的乱码问题!特别是对于数据库的写入操作!