Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package be.khk.lesson;
- import be.khk.lesson.beans.*;
- import be.khk.lesson.dataaccess.*;
- import java.io.IOException;
- import java.net.URL;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import javax.servlet.RequestDispatcher;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- *
- * @author goqu
- */
- public class AdminServlet extends HttpServlet {
- private DAAdministrator daAdministrator = null;
- private DAInstitute daInstitute = null;
- private DACountry daCountry = null;
- public void init(ServletConfig config) throws ServletException {
- try {
- String url = config.getInitParameter("url");
- String password = config.getInitParameter("password");
- String login = config.getInitParameter("login");
- String driver = config.getInitParameter("driver");
- daAdministrator = new DAAdministrator(url, login, password, driver);
- daInstitute = new DAInstitute(url, login, password, driver);
- daCountry = new DACountry(url, login, password, driver);
- } catch (Exception e) {
- throw new ServletException(e);
- }
- }
- public void destroy() {
- try {
- if (daAdministrator != null) {
- daAdministrator.close();
- }
- if (daInstitute != null) {
- daInstitute.close();
- }
- if (daCountry != null) {
- daCountry.close();
- }
- } catch (SQLException e) {
- }
- }
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- RequestDispatcher rd = null;
- String username = request.getParameter("username");
- String password = request.getParameter("password");
- //String landid = request.getParameter("landId");
- Administrator administrator = daAdministrator.getAdministrator(username, password);
- //if (administrator.getId() > 0) {
- ArrayList<Country> countries = daCountry.getCountry();
- request.setAttribute("boodschap", "login is gelukt");
- request.setAttribute("countries", countries);
- String test = request.getParameter("testvar");
- request.setAttribute("test", test);
- int countryId = Integer.parseInt(request.getParameter("countryId"));
- request.setAttribute("countryId", countryId);
- rd = request.getRequestDispatcher("testadmin.jsp");
- /*} else {
- request.setAttribute("boodschap", "login is mislukt");
- rd = request.getRequestDispatcher("index.jsp");
- }*/
- //if (request.getParameter("countryId") != null) {
- /* int countryId = Integer.parseInt(request.getParameter("countryId"));
- ArrayList<Institute> institutes = daInstitute.getInstituteByCountryId(countryId);
- request.setAttribute("institutes", institutes);
- request.setAttribute("countryId", countryId);
- rd = request.getRequestDispatcher("testadmin.jsp");
- //}*/
- rd.forward(request, response);
- }
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- }
Add Comment
Please, Sign In to add comment