blob: e7908d5b91c86dae9993383b69f907882c48f67b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package com.example.spring.bank.web;
import java.io.IOException;
import java.math.BigDecimal;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.example.spring.bank.AccountManager;
/**
* Servlet implementation class BankGateway
*/
public class BankGateway extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public BankGateway() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
getServletContext().getRequestDispatcher("/deposit.jsp").forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
AccountManager am = ctx.getBean("accountManager", AccountManager.class);
int accountNumber = Integer.parseInt(request.getParameter("accountNumber"));
BigDecimal amount = new BigDecimal(request.getParameter("amount"));
// How to use a session scoped bean (Example only)
// DepositForm form = (DepositForm) ctx.getBean("depositForm");
// form.setAccountNumber(accountNumber);
// form.setAmount(amount);
// End of example
am.deposit(accountNumber, amount);
// We can dispatch to a success page if we prefer!
getServletContext().getRequestDispatcher("/deposit.jsp").forward(request, response);
}
}
|