Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ServletLevel extends HttpServlet {
- private static final long serialVersionUID = 1L;
- private LevelDAOImpl levelDAOImpl;
- public void init() {
- String jdbcURL = getServletContext().getInitParameter("jdbcURL");
- String jdbcUsername = getServletContext().getInitParameter("jdbcUsername");
- String jdbcPassword = getServletContext().getInitParameter("jdbcPassword");
- DbConnection dbConnection = new DbConnection(jdbcURL, jdbcUsername, jdbcPassword);
- levelDAOImpl= new LevelDAOImpl(dbConnection);
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doGet(request, response);
- }
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- String action = request.getServletPath();
- try {
- switch (action) {
- case "/newL":
- showNewForm(request, response);
- break;
- case "/insertL":
- insertLevel(request, response);
- break;
- case "/deleteL":
- deleteLevel(request, response);
- break;
- case "/editL":
- showEditForm(request, response);
- break;
- case "/updateL":
- updateLevel(request, response);
- break;
- case "/listL":
- listLevel(request, response);
- break;
- default:
- listLevel(request, response);
- break;
- }
- } catch (SQLException ex) {
- throw new ServletException(ex);
- }
- }
- private void listLevel(HttpServletRequest request, HttpServletResponse response)
- throws SQLException, IOException, ServletException {
- List<Level> listLevel = levelDAOImpl.GetAll();
- request.getSession().setAttribute("listLevel", listLevel);
- request.getRequestDispatcher("Level.jsp").forward(request, response);
- }
- private void showNewForm(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- RequestDispatcher dispatcher = request.getRequestDispatcher("AddLevel.jsp");
- dispatcher.forward(request, response);
- }
- private void showEditForm(HttpServletRequest request, HttpServletResponse response)
- throws SQLException, ServletException, IOException {
- int id_level = Integer.parseInt(request.getParameter("id_level"));
- Level existingLevel = levelDAOImpl.getId(id_level);
- RequestDispatcher dispatcher = request.getRequestDispatcher("AddLevel.jsp");
- request.setAttribute("level", existingLevel);
- dispatcher.forward(request, response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement