Controleur.java
1.48 KB
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
package web.controleurs;
import java.io.IOException;
import ejb.sessions.* ;
import ejb.entites.* ;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(value={"rechCompte","afficherCompte"})
public class Controleur extends HttpServlet {
private static final long serialVersionUID = 1L;
@javax.ejb.EJB private ServiceBanqueLocal service ;
public Controleur() {}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String url = request.getRequestURL().toString();
String maVue ="/rechCompte.html"; // vue par défaut
if (url.endsWith("/rechCompte")) {
maVue ="/rechCompte.html"; // rien d'autre à faire
} else if (url.endsWith("/afficherCompte")) {
maVue = "/afficherCompte.jsp";
int numeroCompte=Integer.parseInt(request.getParameter("numeroCompte")) ;
Compte compte ;
try {
compte= service.getCompte(numeroCompte);
java.util.Collection<LigneAction> l_la = service.getActionsAchetees(numeroCompte);
request.setAttribute("listeLA", l_la);
} catch (CompteInconnuException e) {
compte=null ;
}
request.setAttribute("compte",compte) ;
}
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(maVue);
dispatcher.forward(request,response);
}
}