当前位置: 代码迷 >> Java Web开发 >> jsp登录检测的500-异常
  详细解决方案

jsp登录检测的500-异常

热度:704   发布时间:2016-04-17 11:11:53.0
jsp登录检测的500-错误
我做的jsp登录页面
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="GB2312"%>


<html>
  <head>  
   

   
</head>
<body>
  <center><h1>管理员登陆</h1></center><BR/>
  
  <form name="f1" id="f1" action="guanliyuanjiance.jsp" method="post">
  <table border="0" align=center>
  <tr>
  <td>用户:</td>
  <td>
  <input type="text" name="username" id="username" value=""></td>
  </tr>
  <tr>
  <td>密码:</td>
  <td>
  <input type="passwd" name="passwd" id="passwd" value=""></td>
  </tr> 
  <tr>
  <td colspan="2" align="center">
  <input type="submit" value="登陆"></td>
  </tr>
   
  </table>
  <table align="center">
  <a href="index.jsp">返回首页</font></a>
   
  </table>
  </form>
  </body>
  
</html>
检测页面
<%@ page language="java" import="java.util.*,java.sql.*" 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 'guanliyuanjiance.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 a=request.getParameter("username");
  String b=request.getParameter("passwd");
  %>
  <%
  //1,加载驱动 
  Class.forName("com.microsoft.jdbc.sqlserver.SqlServerDriver");
  //2,得到连接 
  Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;DatabaseName=userdb","jie","123");
  //3,创建Statement
  Statement stmt=conn.createStatement();
  //4,查询 
  ResultSet rs=stmt.executeQuery("SELECT username from admin WHERE username='"+a+"'");
  //5,执行
  if(rs.next()){
  //说明用户名存在
  if(rs.getString(1).equals(b)){
  //一定合法
  response.sendRedirect("guanliyuan.jsp");
  }else{
  //密码错误
  response.sendRedirect("guanliyuandenglu.jsp");
  相关解决方案