package com.PIM.dao;
public class UserDao {
public boolean exsit(String name) throws SQLException {
Connection conn=DBUtil.getConnection();
String sql="" +
" select * from imooc_goddess " +
" where user_name=? ";
PreparedStatement ptmt=conn.prepareStatement(sql);
ptmt.setString(1, name);
ResultSet rs=ptmt.executeQuery();
if(rs!=null){
return true;
}
else{
return false;
}
}
jsp 页面:
<%@ page language="java" import="java.util.* ,com.PIM.dao.*,com.PIM.model.*" contentType ="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String password = null;
request.setCharacterEncoding("utf-8"); //只是针对POST方式提交的请求,对GET方式无效。
response.setContentType("text/html;charset=utf-8");
UserDao ud= new UserDao();
//报错的地方~~~~~~~~~~~~~~~!!!!!!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boolean a = ud.exsit("565203087");//写死,数据库中有这条数据。但是调用总是报错。
if(a){
request.getRequestDispatcher("main.jsp").forward(request,response);//服务器内部转发
}
else{
response.sendRedirect("Registion.jsp");//请求重定向
}
%>
main 方法:
UserDao ud = new UserDao();
boolean a = ud.exsit("565203087");
System.out.println(a);
//一切正常,服务台能返回true
敞篷帅哥
相关分类