中文问题,怎么都不行
hzqq 2003-07-09 09:00:59 代码如下,总是出现???
用的是mysql
<%@ page language="Java" import="java.sql.*" %>
<%@ page contentType="text/html; charset=GBK" %>
<jsp:useBean id="sqlbean" scope="session" class="mysqlbean.mysqlbean"/>
<%
String uid=(String)session.getAttribute("username");
if (uid==null)response.sendRedirect("login.jsp");
String detail=request.getParameter("detail");
String state=sqlbean.toChinese(request.getParameter("state"));
String comment=sqlbean.toChinese(request.getParameter("comment"));
if (detail!="")
{
String sql="INSERT INTO `event` ( `id` , `userid` , `when` , `detail` , `comment` , `state` ) VALUES ('', '"+uid+"',NOW(),'"+detail+"', '"+comment+"','"+state+"')";
sqlbean.execNoResult(sql);
response.sendRedirect("page.jsp");
}
else
{%>
<script language="JavaScript">
alert("请填写详细内容");
window.location="page.jsp";
</script>
<%
}
%>
toChinese代码
public static String toChinese(String strvalue)
{
try{
if(strvalue==null)
return null;
else
{
strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
return strvalue;
}
}
catch(Exception e)
{
return null;
}
}