81,122
社区成员




<%@ page language="java" import="java.util.*,java.sql.*,com.wjf.model.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'loginCl.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String u = request.getParameter("username");
String p = request.getParameter("password");
UserBeanCl ubc = new UserBeanCl();//说这儿cannot be resolved to a type
if(ubc.check(u,p)){
response.sendRedirect("wel.jsp?username_to_wel="+u);
}else{
response.sendRedirect("login.jsp");
}
%>
</body>
</html>
package com.wjf.model;
import java.sql.*;
public class UserBeanCl {
private Connection co = null;
private PreparedStatement st = null;
private ResultSet rs = null;
//验证用户是否合法
public boolean check(String u,String p){
boolean b = false;
co = new ConnDB().getConn();
try{
st = co.prepareStatement("select passwd from users where userName=?");
st.setString(1,u);
ResultSet rs = st.executeQuery();
if(rs.next()){
if(rs.getString(1).equals(p)){
b=true;
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
return b;
}
public void close(){
try{
if(rs != null){
rs.close();
rs = null;
}
if(st != null){
st.close();
st = null;
}
if(co != null){
co.close();
co = null;
}
}catch(Exception e){
e.printStackTrace();
}
}
}