50分,全部拿出来,简单的JSP问题

来源:百度知道 编辑:UC知道 时间:2024/05/20 22:49:38
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import=" java.sql.*"%>
<html>
<head>
<title>管理员登录验证</title>
<head>

<center>
<h1>管理员登录验证</h1>
<hr>
<br>
<%! String DBDRTVER="sun.jdbc.odbc.JdbcOdbcDriver";
String DBURL="jdbc:odbc:personperson";
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;

%>
<%
String go=request.getParameter("go");
String id=request.getParameter("id");
String password=repuest.getParameter("password");
String sql="SELECT name FORM person WHERE id=? and password=?"
boolean flag=false;
if(go==null)go="";
if(id==null)id="";
if(password==null)password="";
if(go.equals("ok"

首先 你最好把这些代码转移到SERVLET里 这样写是很不好的习惯

用ResultSet创建个对象 获得查询后的数据 比方说

if(id!=null&id.equals("")password!=null&password.equals("")){
//在这里进行过是否为空的验证 之后
String str = "select * 表名 where 然后用你获得的ID和PASSWORD进行查询

查询结束后 用ResultSet创建一个方法 比如
ResultSet rs = 查询结果
然后用WHILE
while(rs.next){
}
如果说能运行下去 就说明在库里找到了这个值 如果没有运行 那么就说名没有这个值

}