-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefaultController.java
47 lines (36 loc) · 1.5 KB
/
DefaultController.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.leapfrog.academy.controller;
import com.leapfrog.academy.dbutil.DbConnection;
import com.leapfrog.academy.entity.Course;
import com.leapfrog.academy.service.CourseService;
import com.leapfrog.academy.service.impl.CourseServiceImpl;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author admin
*/
@WebServlet(name = "default" ,urlPatterns = {"/"})
public class DefaultController extends HttpServlet {
CourseService courseService=new CourseServiceImpl();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
response.setHeader("Content-Type", "text/html");
try{
request.setAttribute("courses",courseService.getAll(false));
request.getRequestDispatcher("/WEB-INF/Views/front/index.jsp").forward(request, response);
}catch(Exception e){
out.println("<h1>" + e.getMessage()+ "</h1>");
}
}
}