jsp中调用bean:以下是bean里面的方法
public void executeUpdate(String sql)throws Exception{
sql=new String(sql.getBytes("GBK"),"ISO8859_1");
try{
conn=DriverManager.getConnection(sConnStr,username,password);
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
conn.close();
stmt.close();
}
catch(SQLException ex){
System.out.println("sql.executeUpdate:"+ex.getMessage());
}
}
这样做也不行!!!
public void executeUpdate(String sql)throws Exception{
sql=new String(sql.getBytes("GBK"),"ISO8859_1");
try{
conn=DriverManager.getConnection(sConnStr,username,password);
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
conn.close();
stmt.close();
}
catch(SQLException ex){
System.out.println("sql.executeUpdate:"+ex.getMessage());
}
}
这样做也不行!!!
试试吧
这样应该就可以了,这是编码原因造成的。关于过滤器,tomcat下有一个例子。
http://www.blogjava.net/rickhunter/articles/33571.html
public String GBToUnicode(String strIn)
{
String strOut = null;
if(strIn == null || (strIn.trim()).equals(""))return strIn;
try{
byte[] b = strIn.getBytes("ISO8859_1");
strOut = new String(b,"GBK");
}
catch(Exception e)
{}
return strOut;
}
%>