以下是一个关于注册用户的页面,可是不管是否输入内容它总是写到数据库中。请高手看看哪有问题。
<%@ include file="convert.jsp"%>
<%
String username=Bytes(request.getParameter("username"));
String password=Bytes(request.getParameter("password"));
String sex=Bytes(request.getParameter("sex"));
String age=Bytes(request.getParameter("age"));
boolean notkong=true;
Connection conn=null;
Statement stmt=null;
int rs;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String path="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bin";
String struser="sa";
String pwd="";
conn=DriverManager.getConnection(path,struser,pwd);
stmt=conn.createStatement();
if (username!=null && username!="")
{
String sql="insert into users values('"+username+"','"+password+"','"+sex+"','"+age+"')";
rs=stmt.executeUpdate(sql);
}
}
catch(SQLException e)
{
out.print(e.getMessage());
}
catch(Exception e)
{
out.print(e.getMessage());
}
finally
{
try
{
if (conn!=null)
conn.close();
}
catch(Exception e)
{
}
}
%>
convert.jsp内容为下
<%!
public String Bytes(String str)
{
try
{
String strOld=str;
byte[] strNew=strOld.getBytes("ISO8859-1");
String bytes=new String(strNew);
return bytes;
}
catch(Exception e){}
return null;
}
%>