|
//////////Log in 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">Yuanmeng IT Book Ordering Net</h1>
</div></td>
</tr>
<tr>
<td width="325"> </td>
<td width="131"><div align="center">User name: </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">Secret code:</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="log in" />
<input name="guest" type="submit" value="Guest">
<span class="STYLE3">[Note:] Logging in as the default guest will not be eligible for membership discounts</span> </p>
</td>
<td> </td>
To
</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 {
To
String pass=null, uname=null;
// Get the HttpSession object.
HttpSession session = req.getSession();
To
// 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);
}
To
// Get the username and password parameters.
pass = req.getParameter("password");
uname = req.getParameter("username");
To
// Invalidate the session to get rid of any old Member or Librarian objects.
session.invalidate();
To
// Get a fresh session.
session = req.getSession();
To
// Create a new library member through validation. If the uname is not valid, the member is null.
Member member = null;
To
try {
String ssn=(String)session.getAttribute("username");
String passWord=(String)session.getAttribute("password");
String sql = "SELECT * FROM Member WHERE ID = "+ ssn +
"AND password ='" + passWord + "'";
To
ResultSet r = db.runQuery(sql);
To
//member = db.validateMember( uname, pass );
/*} catch( Exception e ){
}
To
try {*/
// The member is not null, so he must have been validated. Place the member into the session.
if (r!=null) {
To
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.
To
}
}
}
After clicking login, I link to http://localhost:8090/MyBookStore/MemberLoginController to find the servlet but why is it blank? How to debug? |
|