为什么在向数据库中提交留言前都有空行 急需 谢谢大家啊
做一个提交留言的页面,每次提交到数据库中后,这条留言的上面一条信息的空的,为什么啊?代码如下:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>录入留言</title>
</head>
<body>
<%@ include file="a.jsp" %>
<form name="form1" method="post" action="">
<p>写留言: </p>
<p>
<textarea name="content" rows="10"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="留言" />
</p>
<p> </p>
</form>
<%
String content=request.getParameter("content");
if(content==null)
{content="";
}
byte d[]=content.getBytes("ISO-8859-1");
content=new String(d);
try{String basicmessage=
"INSERT INTO detail (realname,content) VALUES ("+"'"+account+"','"+content+"' )";
sql.executeUpdate(basicmessage);
out.print("<BR>留言成功" );
con.close(); }
catch(SQLException e)
{out.print("<BR>不允许输入空值");
}
%>
</body>
</html>
a.jsp
<%!//处理字符串的一个常用方法:
public String getString(String s)
{ if(s==null) s="";
try {byte a[]=s.getBytes("ISO-8859-1");
s=new String(a);
}
catch(Exception e)
{ }
return s;
}
%>
<% //为了防止客户直接进入该页面,首先从session对象获取密码和帐号信息:
String account=(String)session.getAttribute("account");
if(account==null)
{account="";
}
byte b[]=account.getBytes("ISO-8859-1");
account=new String(b);
String secret=(String)session.getAttribute("secret");
if(secret==null)
{secret="";
}
byte c[]=secret.getBytes("ISO-8859-1");
secret=new String(c);
//查询数据库信息,验证身份:
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException event){}
try
{String URL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ly";
con = DriverManager.getConnection(URL,"sa","");
sql=con.createStatement();
String condition="SELECT * FROM yh WHERE username = "+"'"+account+"'";
rs =sql.executeQuery(condition);
if(rs.next()) {
String s=rs.getString(2);
if (secret.equals(s))
{
}else
{ response.sendRedirect("denglu.jsp");
}
} else {response.sendRedirect("denglu.jsp");} }
catch(SQLException e1) {}
%>