daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest May 23rd, 2018 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package controller;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5. import java.sql.SQLException;
  6.  
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9. import javax.servlet.ServletConfig;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.annotation.WebServlet;
  12. import javax.servlet.http.HttpServlet;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15.  
  16. import javax.servlet.http.HttpSession;
  17. import ko.stage.KCompte;
  18.  
  19. import ko.stage.KDroit;
  20. import net.ko.framework.Ko;
  21. import net.ko.framework.KoHttp;
  22. import net.ko.kobject.KListObject;
  23. import net.ko.kobject.KSession;
  24. import net.ko.ksql.KDBMysql;
  25.  
  26. /**
  27.  * Servlet implementation class NetController
  28.  */
  29. @WebServlet("*.do")
  30. public class NetController extends HttpServlet {
  31.  
  32.     private static final long serialVersionUID = 1L;
  33.     KSession ks;
  34.     private static String host = "localhost";
  35.     private static String login = "root";
  36.     private static String mdp = "lall";
  37.     private static String bdd = "stage";
  38.  
  39.     /**
  40.      * @see HttpServlet#HttpServlet()
  41.      */
  42.     public NetController() {
  43.         super();
  44.         // TODO Auto-generated constructor stub
  45.     }
  46.  
  47.     /**
  48.      * @see Servlet#init(ServletConfig)
  49.      */
  50.     @Override
  51.     public void init(ServletConfig config) throws ServletException {
  52.  
  53.         Ko.ConstraintsDepth = 2;
  54.  
  55.  
  56.     }
  57.  
  58.     @Override
  59.     protected void service(HttpServletRequest request, HttpServletResponse response) {
  60.         try {
  61.             processAction(request, response);
  62.         } catch (Throwable ex) {
  63.             Logger.getLogger(NetController.class.getName()).log(Level.SEVERE, null, ex);
  64.         }
  65.     }
  66.  
  67.     /**
  68.      * Gère le module Données de Structure
  69.      * @param request
  70.      * @param response
  71.      * @throws Throwable
  72.      */
  73.     private void goDonStruc(HttpServletRequest request, HttpServletResponse response) throws Throwable {
  74.         request.setAttribute("vue", "ds/donStruc.jsp");
  75.         if (request.getParameter("onglet") != null) {
  76.             switch (Integer.parseInt(request.getParameter("onglet"))) {
  77.                 case 1:
  78.                     request.setAttribute("chemin", "etudiant.jsp");
  79.  
  80.                     break;
  81.                 case 2:
  82.                     request.setAttribute("chemin", "promotion.jsp");
  83.  
  84.                     break;
  85.                 case 3:
  86.                     request.setAttribute("chemin", "typedecompte.jsp");
  87.                     break;
  88.                 case 4:
  89.                     request.setAttribute("chemin", "entreprise.jsp");
  90.             }
  91.  
  92.         }
  93.         forwardView("index.jsp", request, response);
  94.     }
  95.  
  96.     private void goGestDroits(HttpServletRequest request, HttpServletResponse response) throws Throwable {
  97.         request.setAttribute("vue", "droits/gestDroits.jsp");
  98.         if(request.getParameter("onglet")!= null){
  99.            
  100.             switch(Integer.parseInt(request.getParameter("onglet"))){
  101.                 case 1:
  102.                     request.setAttribute("chemin","compte.jsp" );
  103.                     break;
  104.                 case 2:
  105.                     request.setAttribute("chemin", "droit.jsp");
  106.                     break;
  107.                 case 3:
  108.                     request.setAttribute("chemin", "module.jsp");
  109.                     break;
  110.                    
  111.             }
  112.         }
  113.         forwardView("index.jsp", request, response);
  114.     }
  115.    
  116.     private void goGestStageEtu(HttpServletRequest request, HttpServletResponse response) throws Throwable {
  117.         request.setAttribute("vue", "stageEtudiant/gestStageEtu.jsp");
  118.         if(request.getParameter("onglet")!= null){
  119.            
  120.             switch(Integer.parseInt(request.getParameter("onglet"))){
  121.                 case 1:
  122.                     request.setAttribute("chemin","entreprise.jsp" );
  123.                     break;
  124.                 case 2:
  125.                     request.setAttribute("chemin", "stageEtudiant.jsp");
  126.                     break;                    
  127.             }
  128.         }
  129.         forwardView("index.jsp", request, response);
  130.     }
  131.    
  132.     private void goGestProspection(HttpServletRequest request, HttpServletResponse response) throws Throwable {
  133.         request.setAttribute("vue", "prospections/gestPro.jsp");
  134.         if(request.getParameter("onglet")!= null){
  135.            
  136.             switch(Integer.parseInt(request.getParameter("onglet"))){
  137.                 case 1:
  138.                     request.setAttribute("chemin","entreprise.jsp" );
  139.                     break;
  140.                 case 2:
  141.                     request.setAttribute("chemin", "prospection.jsp");
  142.                     break;                    
  143.             }
  144.         }
  145.         forwardView("index.jsp", request, response);
  146.     }
  147.     private void goGestStage(HttpServletRequest request, HttpServletResponse response) throws Throwable {
  148.         request.setAttribute("vue", "stages/gestStages.jsp");
  149.         if(request.getParameter("onglet")!= null){
  150.            
  151.             switch(Integer.parseInt(request.getParameter("onglet"))){
  152.                 case 1:
  153.                     request.setAttribute("chemin","periode.jsp" );
  154.                     break;
  155.                 case 2:
  156.                     request.setAttribute("chemin", "stage.jsp");
  157.                     break;
  158.                    
  159.             }
  160.         }
  161.         forwardView("index.jsp", request, response);
  162.     }
  163.  
  164.     private void processAction(HttpServletRequest request, HttpServletResponse response) throws Throwable {
  165.         String action = request.getServletPath();
  166.         if (action.equalsIgnoreCase(("/login.do"))) {
  167.             doLogin(request, response);
  168.         }
  169.         if (action.equalsIgnoreCase("/quitter.do")) {
  170.             request.setAttribute("message", "Au revoir " + request.getSession().getAttribute("user"));
  171.             request.getSession().removeAttribute("user");
  172.             forwardView("vue2.jsp", request, response);
  173.         }
  174.         if (action.equalsIgnoreCase("/donStruc.go")) {
  175.             goDonStruc(request, response);
  176.         }
  177.  
  178.         if (action.equalsIgnoreCase("/gestDroits.go")) {
  179.             goGestDroits(request, response);
  180.         }
  181.  
  182.         if (action.equalsIgnoreCase("/gestStagesEtu.go")) {
  183.             goGestStageEtu(request, response);
  184.         }
  185.        
  186.         if (action.equalsIgnoreCase("/gestStages.go")) {
  187.             goGestStage(request, response);
  188.         }
  189.        
  190.         if (action.equalsIgnoreCase("/gestProspections.go")) {
  191.             goGestProspection(request, response);
  192.         }
  193.        
  194.         else {
  195.             request.setAttribute("vue", "default.jsp");
  196.             forwardView("index.jsp", request, response);
  197.  
  198.  
  199.         }
  200.     }
  201.  
  202.     /**
  203.      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  204.      */
  205.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  206.     }
  207.  
  208.     private boolean beforeRequest(HttpServletRequest request, HttpServletResponse response) throws SQLException {
  209.         HttpSession session = request.getSession();
  210.         if (request.getMethod().equalsIgnoreCase("post")) {
  211.             if (request.getParameter("login") != null) {
  212.             }
  213.         }
  214.         return session.getAttribute("login") != null;
  215.     }
  216.  
  217.     private void doLogin(HttpServletRequest request, HttpServletResponse response) throws Throwable {
  218.         connection(request.getParameter("login"), request.getParameter("pass"), request);
  219.         forwardView("index.jsp", request, response);
  220.     }
  221.  
  222.     private void forwardView(String viewName, HttpServletRequest request, HttpServletResponse response) throws Throwable {
  223.         if (viewName.endsWith(".jsp")) {
  224.             request.getRequestDispatcher(viewName).forward(request,
  225.                     response);
  226.         } else {
  227.             throw new IllegalStateException("impossible d'afficher la vue: " + viewName);
  228.         }
  229.     }
  230.  
  231.     private boolean connection(String login, String pass, HttpServletRequest request) throws SQLException {
  232.         try {
  233.             KCompte user = new KCompte();
  234.             user.loadOne(KoHttp.kdatabase(), "login='" + login + "' AND password='" + pass + "'");
  235.             HttpSession session = request.getSession();
  236.             session.setAttribute("login", user.getLogin());
  237.             session.setAttribute("type", user.getTypecompte().getLibelle());
  238.             session.setAttribute("droit", user.getTypecompte().getDroits());
  239.  
  240.             return true;
  241.         } catch (InstantiationException ex) {
  242.             Logger.getLogger(NetController.class.getName()).log(Level.SEVERE, null, ex);
  243.         } catch (IllegalAccessException ex) {
  244.             Logger.getLogger(NetController.class.getName()).log(Level.SEVERE, null, ex);
  245.         } catch (ClassNotFoundException ex) {
  246.             Logger.getLogger(NetController.class.getName()).log(Level.SEVERE, null, ex);
  247.         }
  248.         return false;
  249.     }
  250.  
  251.     /**
  252.      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  253.      */
  254.     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  255.         // TODO Auto-generated method stub
  256.     }
  257.  
  258.     public static boolean verifPerm(String url, HttpSession session) {
  259.         KListObject<KDroit> droit = (KListObject<KDroit>) session.getAttribute("droit");
  260.         for (KDroit right : droit) {
  261.             if (url.equalsIgnoreCase(right.getModule().getUrl()));
  262.             return true;
  263.         }
  264.         return false;
  265.     }
  266. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top