-
package dao;
import tion;
import edStatement;
import
Set;
import eption;
import
import seUtil;
public class UserDao {
public User login(String
username,String pwd){
User user=null;
//
获取数据库连接
Connection conn=nection();
String sql=
try {
PreparedStatement ps=eStatement(sql);
ing(1, username);
ing(2,
pwd);
//
用
ResultSe
t
存储查到的内容
ResultSet rs=eQuery();
if(()){//
查到了数据
user =new User();
}
}
}
}
rn
ame(ing(
代
表
的
是
tb_user
表
的
p>
sword(ing(
(ing(
ne(i
ng(
il(ing(
username
字段
//
将用户名和密码带入到占位符?中
// TODO Auto-generated catch block
tackTrace();
} catch
(SQLException e) {
return user;
package servlet;
import ption;
import tException;
import
vlet;
import rvlet;
import
rvletRequest;
import rvletResponse;
import o;
import
;
/**
* Servlet implementation class
LoginServlet
*/
@WebServlet(
门牌号
public class LoginServlet extends
HttpServlet {
/**
* @see
HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void
doGet(HttpServletRequest request,
HttpServletResponse response) throws
ServletException,
}
// TODO Auto-generated
method stub
ter().append(
private static
final long serialVersionUID = 1L;
IOException {
}
/**
* @see
HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void
doPost(HttpServletRequest request,
HttpServletResponse response) throws
ServletException,
}
//
设置字符编码
< br>racterEncoding(
//
获取页面的账号和
密码
String username=ameter(
p>
对应前台
name
属性
String password=ameter(
n(
账号:
密码:
UserDao dao=new UserDao();
User user=(username, password);
//
判断用户名是否正确
if(user!=null){//
跳转登陆成功的页面
}
//
将
user
对象通过
session
p>
传递到前台页面
sion().setA
ttribute(
uestDispatcher(
uest
Dispatcher(
IOException {
}else{//
跳失败页面
package utils;
import tion;
import Manager;
import eption;
/**
*
*
数据库联连接工具类
*/
public class
DataBaseUtil {
public static Connection
getConnection(){
Connection conn=null;
//
获取驱动
try {
e(
String
url=
conn=nection(url,
}
}
/**
} catch (Exception e) {
}
return conn;
// TODO Auto-generated catch block
tackTrace();
*
数据库关闭连接方法
* @param conn
*/
public static void
closeConnection(Connection conn){
}
try {
}
();
// TODO Auto-generated
catch block
tackTrace();
}
catch (SQLException e) {
package
entity;
/**
*
用户类
*
@author
Administrator
*
*/
public
class
User {
private
int
id
;
private
String
username
;
private
String
password
;
private
String
sex
;
private
String
phone
;
private
String
email
;
public
int
getId() {
}
public
void
setId(
int
id
) {
}
public
String
getUsername() {
return
username
;
this
.
id
=
id
;
return
id
;
}
}
public
void
setUsername(String
username
) {
}
public
String
getPassword() {
}
public
void
setPassword(String
password
) {
}
public
String
getSex() {
}
public
void
setSex(String
sex
) {
}
public
String
getPhone() {
}
public
void
setPhone(String
phone
) {
}
public
String
getEmail() {
}
public
void
setEmail(String
email
) {
}
th
is
.
email
=
email
;
return
email
;
this
.
phone
=
phone
;
return
phone
;
this
.
sex
=
sex
;
return
sex
;
this
< br>.
password
=
password
;
return
password
;
this
.
username
=
username
;
package
servlet;
import
ption;
import
ation;
import
tContext;
import
tException;
import
vlet;
import
rvlet;
import
rvletRequest;
import
rvletResponse;
import
ssion;
-
-
-
-
-
-
-
-
-
上一篇:LTE测量与切换详细解读
下一篇:4G基础知识百问汇总(100题)