为什么跳转后的验证登陆的界面出错了?
登陆界面的主要代码:
<form name="login" action="Login.jsp" method="post" onSubmit="return Check()">
<label for="">Username:</label> <input type="text" name="username" size="15" value="" /><br />
<br />
<label for="">Password:</label> <input type="password" name="password" size="15" value="" /><br />
<table>
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="Manage" tabindex="4" /><label for="RadioButtonList1_0">部门</label></td><td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="Teacher" tabindex="4" /><label for="RadioButtonList1_1">教师</label></td><td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="Student" checked="checked" tabindex="4" /><label for="RadioButtonList1_2">学生</label></td>
</tr>
</table>
<input type="submit" name="submit" value="登录" />
<input type="reset" name="reset" value="重置" />
<script language="JavaScript" type="text/javascript">
function Check() {
if(document.login.username.value == "") {
window.alert("账号不能为空!");
return false;
}
else if(document.login.password.value == "") {
window.alert("密码不能为空!");
return false;
}
}
</script>
</form>
-------------------------------------------------------------------------------------------------
后台验证的代码:
<%@ page language="java" contentType="text/html; charset=gbk" errorPage="" pageEncoding="gbk"%>
<%@ page import = "cn.jbit.output.*" %>
<%@ page import="java.sql.*,java.io.*"%>
<jsp:useBean id="rst" class="cn.jbit.output.Rs_DB" scope = "page"/>
<html>
<body>
<%
String username = (String)request.getParameter ("username");
String password = (String)request.getParameter ("password");
String userinfo = (String)request.getParameter("RadioButtonList1");
out.println(username);
out.println(password);
out.println(userinfo);
String sql = "select * from " + userinfo + " where username ='" + username + "' and password = '" + password +"'";
ResultSet rs = rst.getResult(sql);
if (!rs.next()) {
rs.close();
out.println("<script language = 'javascript'>alert('用户名或密码错误');parent.location.href = 'PleaseLogin.jsp';</script>");
} else {
session.setAttribute("username",rs.getString("username"));
session.setAttribute("password", rs.getString("password"));
rs.close();
if(userinfo == "Student") {
response.sendRedirect("Student.jsp");
} else if(userinfo == "Teacher") {
response.sendRedirect("Teacher.jsp");
} else if(userinfo == "Manage") {
response.sendRedirect("Manage.jsp");
}
}
%>
</body>
</html>
-------------------------------------------------------------------------------------------------
java文件 1 :
package cn.jbit.output;
import java.sql.*;
public class JDBConnection {
public static Connection getConnection() {
String DBDrive = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=SelectClass";
String userName = "sa";
String password = "zhanwenzhao";
Connection conn = null;
try {
Class.forName(DBDrive); // -------forName下面还有一条红线,这是为什么?
conn = DriverManager.getConnection(url,userName,password);
} catch (Exception e) {
e.printStackTrace();
System.out.println("数据库加载失败");
}
return conn;
}
}
----------------------------------------------------------------------------------------------------
java文件 2 :
package cn.jbit.output;
import java.sql.*;
public class Rs_DB {
private Connection conn;
public Rs_DB() {
this.conn = JDBConnection.getConnection();
}
public ResultSet getResult(String str) {
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(str);
return rs;
} catch (Exception e) {
}
return null;
}
}
--------------------编程问答-------------------- 把错误贴出来 --------------------编程问答--------------------
这些是复制的错误提示:
HTTP Status 500 - An exception occurred processing JSP page /Login.jsp at line 4 1: <%@ page language="java" contentType="text/html; charset=gbk" errorPage="" pageEncoding="gbk"%> 2: <%@ page import = "cn.jbit.output.*" %> 3: <%@ page import="java.sql.*,java.io.*"%> 4: <jsp:useBean id="rst" class="cn.jbit.output.Rs_DB" scope = "page"/> 5: <html> 6: <body> 7: <% Stacktrace:
--------------------编程问答-------------------- 各路大神进来看看啊······ --------------------编程问答-------------------- 你那个后台验证页面41行附近有错误,我就不数了,自己检查下! --------------------编程问答--------------------
为什么我的后台验证代码总共就40行?我要检查哪里?
--------------------编程问答-------------------- 问题到底出在哪里啊??? --------------------编程问答-------------------- 4: <jsp:useBean id="rst" class="cn.jbit.output.Rs_DB" scope = "page"/>
第四行出错,看错误,已经有明显提示了 --------------------编程问答--------------------
那要怎么解决的啊? 纠缠了好久 --------------------编程问答-------------------- 我没仔细看你的内容 你看看那一行 你的引号里面的内容是否拼写正确 引号是否是英文模式下的输入(不能是中文的) 你的class路径是否完全正确 是否存在拼写错误等 一定要小心认真 因为拼写错误和输入格式错误 这些都是小的不容易找出来的错误 --------------------编程问答-------------------- 没有导入Bean吧
补充:Java , Web 开发