📄 customerlogincontroller.java
字号:
import bean.*;
import java.io.IOException;
import java.net.URLEncoder;
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 bean.Customer;
/**
* Class <b>CustomerLoginController</b> contains
* the servlet controller functionality for processing
* customer login requests.
*
*
* @author ProjectGroup
* @version 1.0.0
*/
public class CustomerLoginController extends Controller {
/**
* CustomerLoginController 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 {
// Get the session object.
HttpSession session = req.getSession();
// Lets invalidate the session to get rid of the unnecessary objects.
//session.invalidate();
// Get a fresh HttpSession.
// Get the username and password parameters from the customer log in form.
String num = req.getParameter("num");
String passWord = req.getParameter("passwd");
// Attempt to validate the customer.
Customer customer = new Customer();
try {
customer = StoreCustomer.getCustomer(num,passWord);
} catch( Exception e ){
sendErrorRedirect(req, res, e);
}
try {
// Place the customer bean back into the session.
if (customer.getNum()!=null) {
session.setAttribute("customer", customer);
res.sendRedirect("/e-commerce/customeraccount.jsp");
} else {
// If the customer object is null, then validation has failed. Tell this to the user.
res.sendRedirect("/e-commerce/error.jsp");
}
return;
} catch (Exception e) {
// Send the exception to the standard error page.
sendErrorRedirect(req, res, e);
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -