[此贴子已经被作者于2006-8-5 11:43:18编辑过]
俺做出来了,哈哈,不去吃饭,都在这里做,精神可嘉呀,哈哈...
condition.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>查询条件</title>
<style type="text/css">
<!--
.STYLE1 {
font-size: 18px;
font-weight: bold;
color: #6666FF;
}
-->
</style>
</head>
<body>
<div align="center" class="STYLE1">条件查询</div>
<form id="form1" name="form1" method="post" action="select.jsp">
<table width="324" height="109" border="1" align="center" cellspacing="0">
<tr>
<td width="145">姓名:</td>
<td width="169"><label>
<input type="text" name="name" />
</label></td>
</tr>
<tr>
<td>性别:</td>
<td><label>
<input type="text" name="sex" />
</label></td>
</tr>
<tr>
<td>年龄:</td>
<td><label>
<input type="text" name="age" />
</label></td>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
<td><label>
<input type="reset" name="Submit2" value="重置" />
</label></td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
select.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%!
public String codeToString(String str)
{
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%
String sqlString;
String name=codeToString(request.getParameter("name"));
String sex=codeToString(request.getParameter("sex"));
String age=codeToString(request.getParameter("age"));
//if (name==null||name.trim().length()==0)
// sqlString="select * from information where sex like'%"+sex.trim()+"%'"+"and age like '%" +age.trim()+"%'";
//else if (sex==null||sex.trim().length()==0)
// sqlString="select * from information where name like'%"+name.trim()+"%'"+"and age like '%" +age.trim()+"%'";
//else if (age==null||age.trim().length()==0)
// sqlString="select * from information where name like'%"+name.trim()+"%'"+"and sex like '%" +sex.trim()+"%'";
//else
sqlString="select * from information where name like'%"+name.trim()+"%'"+"and sex like '%" +sex.trim()+"%'"+"and age like '%"+age.trim()+"%'";
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>综合查询</title>
</head>
<body>
<%
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e)
{
out.print("找不到类!");
}
//try
//{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://MICROSOF-BJER9M:1433;DatabaseName=basesql","sa","12345");
sql=con.createStatement();
rs=sql.executeQuery(sqlString);
out.print("<table Border>");
out.print("<tr><td colspan=3 align=center>用户数据</td></tr>");
out.print("<tr>");
out.print("<td width=100>"+"用户姓名");
out.print("<td width=100>"+"用户性别");
out.print("<td width=100>"+"用户年龄");
out.print("</tr>");
while(rs.next())
{
out.print("<tr>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.print("<td>"+rs.getString(4)+"</td>");
out.print("</tr>");
}
out.print("</table>");
con.close();
//}
//catch(SQLException e)
//{
//out.print("SQL异常!");
//}
%>
</body>
</html>
以上的代码经调试过,可以运行,表自己建啦
吃饭去啰,要不然,没饭吃了
[此贴子已经被作者于2006-8-5 11:51:13编辑过]