forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetCities.java
More file actions
28 lines (21 loc) · 876 Bytes
/
GetCities.java
File metadata and controls
28 lines (21 loc) · 876 Bytes
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
package com.zetcode.web;
import com.zetcode.bean.City;
import com.zetcode.service.CityService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet(name = "GetCities", urlPatterns = {"/cities"})
public class GetCities extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
List<City> cities = new CityService().findAll();
request.setAttribute("cities", cities);
request.getRequestDispatcher("showCities.jsp").forward(request, response);
}
}