authenticator java_找了一个下午都不知道哪里错。。跪求各位大神帮忙。。。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

ClientDao.java

package com.jim.mystore.dao;

import java.sql.*;

import com.jim.mystore.dbc.DatabaseConnection;

import com.jim.mystore.model.Client;

public class ClientDao {

private DatabaseConnection dbc = null;

private Connection conn = null;

private PreparedStatement pstmt = null;

public ClientDao(){

conn = dbc.getConnection();

}

public boolean doInsert(Client cli)throws Exception{

boolean flag = false;

try{

String sql = "insert into client (name,password,phonenumber,emailaddress,regdate) values(?,?,?,?,NOW())";

this.pstmt = this.conn.prepareStatement(sql);

this.pstmt.setString(1,cli.getName());

this.pstmt.setString(2,cli.getPassword());

this.pstmt.setString(3,cli.getPhonenumber());

this.pstmt.setString(4,cli.getEmailAddres());

if(this.pstmt.executeUpdate()>0){

flag = true;

}

} catch (SQLException e){

e.printStackTrace();

} finally {

try{

this.pstmt.close();

this.conn.close();

} catch(SQLException e ){

e.printStackTrace();

}

}

return flag;

}

public ResultSet findAll(){

ResultSet rs = null;

try{

String sql = "select name from client order by name asc";

this.pstmt = this.conn.prepareStatement(sql);

rs = this.pstmt.executeQuery();

} catch(SQLException e){

e.printStackTrace();

} finally{

try{

this.pstmt.close();

this.conn.close();

} catch(SQLException e){

e.printStackTrace();

}

}

return rs;

}

public ResultSet findOne(String cn){

ResultSet rs = null;

try{

String sql = "select * from client where name=?";

this.pstmt = this.conn.prepareStatement(sql);

this.pstmt.setString(1, cn);

rs = this.pstmt.executeQuery();

} catch(SQLException e){

e.printStackTrace();

} finally{

try{

this.pstmt.close();

this.conn.close();

} catch(SQLException e){

e.printStackTrace();

}

}

return rs;

}

}

DatabaseConnection.java

package com.jim.mystore.dbc;

import java.sql.Connection;

import java.sql.DriverManager;

public class DatabaseConnection {

private Connection conn = null;

public DatabaseConnection(){

try{

Class.forName("com.mysql.jdbc.Driver").newInstance();

conn = DriverManager.getConnection("jdbc:mysql://localhost/mystore","root", "jim1");

} catch(Exception e){

e.printStackTrace();

}

}

public Connection getConnection(){

return this.conn;

}

public void close(){

if(this.conn!=null){

try{

this.conn.close();

} catch(Exception e){

e.printStackTrace();

}

}

}

}

ClientService.java

package com.jim.mystore.service;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.jim.mystore.model.Client;

import com.jim.mystore.dao.ClientDao;

public class ClientService {

private ClientDao cd = null;

public ClientService(){

this.cd = new ClientDao();

}

public boolean doInsert(HttpServletRequest request, HttpServletResponse response)throws Exception{

Client cli = new Client();

try{

cli.setName(request.getParameter("name"));

cli.setPassword(request.getParameter("password"));

cli.setEmailaddress(request.getParameter("emailaddress"));

cli.setPhonenumber(request.getParameter("phonenumber"));

} catch(Exception e){

e.printStackTrace();

}

return cd.doInsert(cli);

}

public List findAll()throws Exception{

List all = new ArrayList();

ResultSet rs = null;

rs = cd.findAll();

Client cli = null;

try{

while(rs.next()){

cli = new Client();

cli.setName(rs.getString(1));

all.add(cli);

}

rs.close();

} catch(SQLException e){

e.printStackTrace();

}

return all;

}

public Client findOne(String cn)throws Exception{

Client cli = null;

ResultSet rs = null;

rs = cd.findOne(cn);

if(rs.next()){

cli = new Client();

cli.setId(rs.getInt(1));

cli.setName(rs.getString(2));

cli.setPassword(rs.getString(3));

cli.setPhonenumber(rs.getString(4));

cli.setEmailaddress(rs.getString(5));

cli.setAddress(rs.getString(6));

cli.setBalance(rs.getDouble(7));

cli.setRegdate(rs.getString(8));

}

rs.close();

return cli;

}

}

LoginCheckServlet.java

package com.jim.mystore.servlet;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import com.jim.mystore.model.Client;

import com.jim.mystore.service.ClientService;

/**

* Servlet implementation class LoginCheck

*/

@WebServlet("/Client/LoginCheckServlet")

public class LoginCheckServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

Client cli = null;

ClientService cs = new ClientService();

public LoginCheckServlet() {

super();

// TODO Auto-generated constructor stub

}

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String name = request.getParameter("name");

String pw = request.getParameter("password");

String pw2 = null;

String ref = null;

try{

this.cli = cs.findOne(name);

if(cli != null){

pw2 = cli.getPassword();

if(!pw2.equals(pw)){

ref = "用户名不存在或者密码错误!";

request.setAttribute("ref", ref);

request.getRequestDispatcher("Login.jsp").forward(request,response);

} else {

HttpSession session = request.getSession();

session.setAttribute("name", name);

session.setAttribute("password", pw2);

request.getRequestDispatcher("loginsuccess.jsp").forward(request,response);

}

} else {

ref = "此用户不存在!";

request.setAttribute("ref", ref);

request.getRequestDispatcher("Login.jsp").forward(request,response);

}

} catch(Exception e){

e.printStackTrace();

}

}

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

this.doGet(request, response);

}

}

分包情况

e3cf1c05c89ed09976cfbad2caf5180c.png

跪求各位大神指教。。。我看了一个下午都找不到错误。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值