|
//////////登陆jsp///////////////////////////////////////////////
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="MyBookStore.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="MyBookStore/styles.css">
<style type="text/css">
<!--
.STYLE1 {color: #663333}
.STYLE3 {font-size: 12px}
-->
</style>
<!-- Copyright 2000,2001,2002 Macromedia, Inc. All rights reserved. -->
</head>
<body>
<table width="978" height="300" border="1" align="left">
<form method="post" action="MemberLoginController">
<tr>
<td colspan="4"><div align="center">
<h1 class="STYLE1">缘梦IT图书定购网</h1>
</div></td>
</tr>
<tr>
<td width="325"> </td>
<td width="131"><div align="center">用户名: </div></td>
<td width="297">
<input name="username" type="text" value="guest" size="20" maxlength="20"></td>
<td width="197"> </td>
</tr>
<tr>
<td> </td>
<td><div align="center">密 码:</div></td>
<td>
<input name="password" type="password" value="12345" size="20" maxlength="20"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<p>
<input name="enter" type="submit" value="登陆" />
<input name="guest" type="submit" value="游客">
<span class="STYLE3">[注:]以默认的guest身份登陆将不能享受会员折扣</span> </p>
</td>
<td> </td>
</tr>
</form>
</table>
</body>
</html>
////////////////////////////////servlet///////////////////////////////////
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import MyBookStore.DBWrapper;
import MyBookStore.Member;
/**
* Class <b>MemberLoginController</b> contains
* the servlet controller functionality for processing
* member login requests.
*
*
* @author CTE
* @version 1.0
*/
public class MemberLoginController extends HttpServlet {
/**
* MemberLoginController doPost method. This is can be called
* by <b>Controller</b> superclass' doGet() method.
* @param req HttpServletRequest servlet request object
* @param res HttpServletResponse servlet response object
* @throws ServletException
* @throws IOException
*/
public void doPost (HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException {
String pass=null, uname=null;
// Get the HttpSession object.
HttpSession session = req.getSession();
// Create a Library object instance.
DBWrapper db = null;
// Create a new instance of the Library object.
try {
db=DBWrapper.Instance();
} catch( Exception e ) {
// sendErrorRedirect(req, res, e);
}
// Get the username and password parameters.
pass = req.getParameter("password");
uname = req.getParameter("username");
// Invalidate the session to get rid of any old Member or Librarian objects.
session.invalidate();
// Get a fresh session.
session = req.getSession();
// Create a new library member through validation. If the uname is not valid, the member is null.
Member member = null;
try {
String ssn=(String)session.getAttribute("username");
String passWord=(String)session.getAttribute("password");
String sql = "SELECT * FROM Member WHERE ID = " + ssn +
" AND password = '" + passWord + "'";
ResultSet r = db.runQuery(sql);
//member = db.validateMember( uname, pass );
/*} catch( Exception e ){
}
try {*/
// The member is not null, so he must have been validated. Place the member into the session.
if (r!=null) {
String idname=r.getString("memberID");
int discount=r.getInt("discount");
member=new Member(idname,discount);
session.setAttribute("member", member);
res.sendRedirect("/MyBookStore/index.jsp");////
} else {
/**
* The member was not validated. We simply
* set an error message, and redirect back to
* the member login page.
*/
res.sendRedirect("/MyBookStore/LoginError.jsp");
}
} catch (Exception e2) {
// Something bad happened, so redirect to the error page.
}
}
}
点击登陆后,链接到了 http://localhost:8090/MyBookStore/MemberLoginController找到servlet但是为什么是空白呢?请问怎么调试?
|
|