📄 listaccounts.java
字号:
package itso.basicweb.control;
import java.io.IOException;
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 itso.bank.model.Customer;
import itso.bank.model.Account;
import itso.bank.facade.Banking;
/**
* @version 1.0
* @author
*/
public class ListAccounts extends HttpServlet {
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
performTask(req, resp);
}
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
performTask(req, resp);
}
public void performTask(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
// Parameters
// Get input parameter and keep it on the HTTP session
String customerNumber = req.getParameter("customerNumber");
HttpSession session = req.getSession();
if (customerNumber == null)
customerNumber = (String) session.getAttribute("customerNumber");
else
session.setAttribute("customerNumber", customerNumber);
// Control logic
// Create the new banking fa鏰de
Banking banking = new Banking();
// Retrieve customer and related accounts
Customer customer = banking.getCustomer(customerNumber);
Account[] accounts = banking.getAccounts(customerNumber);
// Response
// Set the request attributes for future rendering
req.setAttribute("customer", customer);
req.setAttribute("accounts", accounts);
// Call the presentation renderer
getServletContext().getRequestDispatcher("listAccounts.jsp").forward(req, resp);
} catch (Exception e) {
req.setAttribute("message", e.getMessage());
req.setAttribute("forward", "index.html");
getServletContext().getRequestDispatcher("showException.jsp").forward(req, resp);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -