日期:2014-05-17  浏览次数:20944 次

JSP数据库连接与页面跳转问题(代码如下)
<%@ page language="java" pageEncoding="utf-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


<title>聊天用户登录</title>


<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<script language="javascript">
function check() {
if (document.form1.nickName.value == "") {
alert("用户昵称不能为空!");
document.form1.nickName.focus();
return false;
} else if (document.form1.userPassword.value == "") {
alert("密码不能为空");
document.form1.userPassword.focus();
return false;
} else
return true;
}
</script>
</head>

<body>
<table align="center" cellpadding="0" cellspacing="0" border="0"
width="500">
<tr>
<td height="100" colspan="2"
style="font-size: 18px; font-weight: bold" align="center">
聊天用户登录
</td>
</tr>
<!-- 定义一个Form表单,表单提交的后台处理页面为chklogin.jsp -->
<form action="chklogin.jsp" method="post" name="form1" onSubmit="return check()">
<tr>
<td width="222" align="right">
昵称:
</td>
<td width="278">
<!-- 表单中的用户昵称输入框,name属性为nickName,用于后台处理页面,接收用户输入的昵称 -->
<input type="text" name="nickName" style="width: 150">
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td align="right">
密码:
</td>
<td>
<!-- 表单中的用户昵称输入框,name属性为userPassword,用于后台处理页面,接收用户输入的昵称 -->
<input type="password" name="userPassword" style="width: 150">
</td>
</tr>
<tr>
<td colspan="2" align="center" height="30" valign="bottom">
<input type="submit" value="登录">
<input type="reset" value="取消">
</td>
</tr>
</form>
<tr>
<td height="50" valign="bottom" colspan="2">
本聊天系统无须注册,登录成功后系统将自动保存用户名和密码
</td>
</tr>
</table>
</body>
</html>


以上代码是 静态网页 用于提交用户名和密码,下面的是登录信息后台处理页面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="net.chat.*"%>

<!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">
</head>
<jsp:useBean id="check" class="net.chat.CheckLogin" scope="page" />
<body>
<%
request.setCharacterEncoding("GB2312");
String nickName = request.getParameter("nickName");
String userPassword = requ