Guest User

Untitled

a guest
Aug 16th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package be.khk.lesson;
  6.  
  7. import be.khk.lesson.beans.*;
  8. import be.khk.lesson.dataaccess.*;
  9. import java.io.IOException;
  10. import java.net.URL;
  11. import java.sql.SQLException;
  12. import java.util.ArrayList;
  13. import javax.servlet.RequestDispatcher;
  14. import javax.servlet.ServletConfig;
  15. import javax.servlet.ServletException;
  16. import javax.servlet.http.HttpServlet;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19.  
  20. /**
  21. *
  22. * @author goqu
  23. */
  24. public class AdminServlet extends HttpServlet {
  25.  
  26. private DAAdministrator daAdministrator = null;
  27. private DAInstitute daInstitute = null;
  28. private DACountry daCountry = null;
  29.  
  30. public void init(ServletConfig config) throws ServletException {
  31. try {
  32. String url = config.getInitParameter("url");
  33. String password = config.getInitParameter("password");
  34. String login = config.getInitParameter("login");
  35. String driver = config.getInitParameter("driver");
  36. daAdministrator = new DAAdministrator(url, login, password, driver);
  37. daInstitute = new DAInstitute(url, login, password, driver);
  38. daCountry = new DACountry(url, login, password, driver);
  39.  
  40. } catch (Exception e) {
  41. throw new ServletException(e);
  42. }
  43. }
  44.  
  45. public void destroy() {
  46. try {
  47. if (daAdministrator != null) {
  48. daAdministrator.close();
  49. }
  50. if (daInstitute != null) {
  51. daInstitute.close();
  52. }
  53. if (daCountry != null) {
  54. daCountry.close();
  55. }
  56. } catch (SQLException e) {
  57. }
  58. }
  59.  
  60. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  61. throws ServletException, IOException {
  62. response.setContentType("text/html;charset=UTF-8");
  63. RequestDispatcher rd = null;
  64. String username = request.getParameter("username");
  65. String password = request.getParameter("password");
  66. //String landid = request.getParameter("landId");
  67. Administrator administrator = daAdministrator.getAdministrator(username, password);
  68.  
  69. //if (administrator.getId() > 0) {
  70. ArrayList<Country> countries = daCountry.getCountry();
  71. request.setAttribute("boodschap", "login is gelukt");
  72. request.setAttribute("countries", countries);
  73. String test = request.getParameter("testvar");
  74. request.setAttribute("test", test);
  75. int countryId = Integer.parseInt(request.getParameter("countryId"));
  76. request.setAttribute("countryId", countryId);
  77. rd = request.getRequestDispatcher("testadmin.jsp");
  78. /*} else {
  79. request.setAttribute("boodschap", "login is mislukt");
  80. rd = request.getRequestDispatcher("index.jsp");
  81. }*/
  82. //if (request.getParameter("countryId") != null) {
  83. /* int countryId = Integer.parseInt(request.getParameter("countryId"));
  84. ArrayList<Institute> institutes = daInstitute.getInstituteByCountryId(countryId);
  85. request.setAttribute("institutes", institutes);
  86. request.setAttribute("countryId", countryId);
  87. rd = request.getRequestDispatcher("testadmin.jsp");
  88. //}*/
  89. rd.forward(request, response);
  90. }
  91.  
  92. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  93. throws ServletException, IOException {
  94. processRequest(request, response);
  95.  
  96.  
  97. }
  98.  
  99. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  100. throws ServletException, IOException {
  101. processRequest(request, response);
  102.  
  103. }
  104. }
Add Comment
Please, Sign In to add comment