当前位置: 代码迷 >> Java Web开发 >> 按说这样的判断应该不会错呀,为什么还是错了
  详细解决方案

按说这样的判断应该不会错呀,为什么还是错了

热度:4   发布时间:2016-04-16 22:05:52.0
按理说这样的判断应该不会错呀,为什么还是错了?
<%@page import="com.sun.crypto.provider.RSACipher"%>
<%@ page contentType="text/html" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    
    <title>验证数据库</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>
  <%!
  //定义数据库驱动程序
  public static final String DBDRIVER="org.gjt.mm.mysql.Driver";
  //数据库连接地址
  public static final String DBURL="jdbc:mysql://localhost:3306/gongchengpingtai";
  public static final String DBUSER="root";
  public static final String DBPASS="123";
   %>
   <%
   Connection conn=null;
   PreparedStatement pstmt=null;
   ResultSet rs=null;
   boolean flag=false;
   String name=null; 
%>
<% 
try{
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL, DBUSER, DBPASS);
String sql="SELECT userName FROM user WHERE userName=? AND password=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,request.getParameter("id"));
pstmt.setString(2,request.getParameter("passwod"));
rs=pstmt.executeQuery();
if(rs.next()){
name=rs.getString(1);
flag=true;
}
}catch(Exception e){
System.out.println(e);
}finally{
try{
rs.close();
pstmt.close();
conn.close();
}catch(Exception e){}
}
%>
<% 
if(flag){
%>
<jsp:forward page="login_success.jsp">
<jsp:param name="uname" value="<%=name %>"/>
</jsp:forward>
<%
}else{

 %>
 <jsp:forward page="Login_failure.html"></jsp:forward>
 <%
 }
  %>
</body>
</html>
 

跳出去的页面是Login_failure.html

------解决方案--------------------
我已经帮你解决了。。。
  相关解决方案