Skip to content

Commit a4c02d6

Browse files
author
Eugen Paraschiv
committed
minor formatting cleanup
1 parent 33f7b1a commit a4c02d6

8 files changed

Lines changed: 43 additions & 60 deletions

File tree

‎spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,14 @@
88
import javax.servlet.http.HttpServletResponse;
99

1010
public class ExampleOne extends HttpServlet {
11-
12-
private static final long serialVersionUID = 1L;
13-
14-
@Override
15-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
16-
response.setContentType("text/html");
17-
PrintWriter out = response.getWriter();
18-
out.println(
19-
"<!DOCTYPE html><html>" +
20-
"<head>" +
21-
"<meta charset=\"UTF-8\" />" +
22-
"<title>HTML Rendered by Servlet</title>" +
23-
"</head>" +
24-
"<body>" +
25-
"<h1>HTML Rendered by Servlet</h1></br>" +
26-
"<p>This page was rendered by the ExampleOne Servlet!</p>" +
27-
"</body>" +
28-
"</html>"
29-
);
30-
}
11+
12+
private static final long serialVersionUID = 1L;
13+
14+
@Override
15+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
16+
response.setContentType("text/html");
17+
PrintWriter out = response.getWriter();
18+
out.println("<!DOCTYPE html><html>" + "<head>" + "<meta charset=\"UTF-8\" />" + "<title>HTML Rendered by Servlet</title>" + "</head>" + "<body>" + "<h1>HTML Rendered by Servlet</h1></br>" + "<p>This page was rendered by the ExampleOne Servlet!</p>"
19+
+ "</body>" + "</html>");
20+
}
3121
}

‎spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
import javax.servlet.http.HttpServletRequest;
88
import javax.servlet.http.HttpServletResponse;
99

10-
@WebServlet(
11-
name = "ExampleThree",
12-
description = "JSP Servlet With Annotations",
13-
urlPatterns = {"/ExampleThree"}
14-
)
10+
@WebServlet(name = "ExampleThree", description = "JSP Servlet With Annotations", urlPatterns = { "/ExampleThree" })
1511
public class ExampleThree extends HttpServlet {
16-
private static final long serialVersionUID = 1L;
17-
18-
@Override
19-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
20-
String message = request.getParameter("message");
21-
request.setAttribute("text", message);
22-
request.getRequestDispatcher("/jsp/ExampleThree.jsp").forward(request, response);
23-
}
12+
private static final long serialVersionUID = 1L;
13+
14+
@Override
15+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
16+
String message = request.getParameter("message");
17+
request.setAttribute("text", message);
18+
request.getRequestDispatcher("/jsp/ExampleThree.jsp").forward(request, response);
19+
}
2420
}

‎spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@Controller
1111
public class ErrorController {
12-
12+
1313
@RequestMapping(value = "500Error", method = RequestMethod.GET)
1414
public void throwRuntimeException() {
1515
throw new NullPointerException("Throwing a null pointer exception");
@@ -34,19 +34,18 @@ public ModelAndView renderErrorPage(HttpServletRequest httpRequest) {
3434
errorMsg = "Http Error Code : 404. Resource not found";
3535
break;
3636
}
37-
// Handle other 4xx error codes.
37+
// Handle other 4xx error codes.
3838
case 500: {
3939
errorMsg = "Http Error Code : 500. Internal Server Error";
4040
break;
4141
}
42-
// Handle other 5xx error codes.
42+
// Handle other 5xx error codes.
4343
}
4444
errorPage.addObject("errorMsg", errorMsg);
4545
return errorPage;
4646
}
4747

4848
private int getErrorCode(HttpServletRequest httpRequest) {
49-
return (Integer) httpRequest
50-
.getAttribute("javax.servlet.error.status_code");
49+
return (Integer) httpRequest.getAttribute("javax.servlet.error.status_code");
5150
}
5251
}

‎spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
@Controller
1515
public class GeoIPTestController {
1616
private RawDBDemoGeoIPLocationService locationService;
17+
1718
public GeoIPTestController() throws IOException {
18-
locationService
19-
= new RawDBDemoGeoIPLocationService();
19+
locationService = new RawDBDemoGeoIPLocationService();
2020
}
21-
@RequestMapping(value="/GeoIPTest", method = RequestMethod.POST)
21+
22+
@RequestMapping(value = "/GeoIPTest", method = RequestMethod.POST)
2223
@ResponseBody
23-
public GeoIP getLocation(
24-
@RequestParam(value="ipAddress", required=true) String ipAddress) throws Exception {
25-
24+
public GeoIP getLocation(@RequestParam(value = "ipAddress", required = true) String ipAddress) throws Exception {
25+
2626
return locationService.getLocation(ipAddress);
2727
}
2828
}

‎spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import javax.servlet.ServletContext;
1414
import javax.servlet.http.HttpServletResponse;
15-
import java.io.FileNotFoundException;
1615
import java.io.IOException;
1716
import java.io.InputStream;
1817

‎spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ public class GeoIP {
55
private String city;
66
private String latitude;
77
private String longitude;
8-
8+
99
public GeoIP() {
10-
10+
1111
}
12-
12+
1313
public GeoIP(String ipAddress) {
1414
this.ipAddress = ipAddress;
1515
}
16-
16+
1717
public GeoIP(String ipAddress, String city, String latitude, String longitude) {
1818
this.ipAddress = ipAddress;
1919
this.city = city;
@@ -52,5 +52,5 @@ public String getLongitude() {
5252
public void setLongitude(String longitude) {
5353
this.longitude = longitude;
5454
}
55-
55+
5656
}

‎spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
import com.maxmind.geoip2.exception.GeoIp2Exception;
1010
import com.maxmind.geoip2.model.CityResponse;
1111

12-
public class RawDBDemoGeoIPLocationService{
12+
public class RawDBDemoGeoIPLocationService {
1313
private DatabaseReader dbReader;
14-
14+
1515
public RawDBDemoGeoIPLocationService() throws IOException {
1616
File database = new File("your-path-to-db-file");
1717
dbReader = new DatabaseReader.Builder(database).build();
1818
}
19-
19+
2020
public GeoIP getLocation(String ip) throws IOException, GeoIp2Exception {
2121
InetAddress ipAddress = InetAddress.getByName(ip);
2222
CityResponse response = dbReader.city(ipAddress);
23-
23+
2424
String cityName = response.getCity().getName();
2525
String latitude = response.getLocation().getLatitude().toString();
2626
String longitude = response.getLocation().getLongitude().toString();

‎spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@
1010
import com.maxmind.geoip2.exception.GeoIp2Exception;
1111
import com.maxmind.geoip2.model.CityResponse;
1212

13-
1413
public class GeoIpIntegrationTest {
15-
14+
1615
@Test
1716
public void givenIP_whenFetchingCity_thenReturnsCityData() throws IOException, GeoIp2Exception {
1817
File database = new File("your-path-to-db-file");
1918
DatabaseReader dbReader = new DatabaseReader.Builder(database).build();
20-
19+
2120
InetAddress ipAddress = InetAddress.getByName("your-public-ip");
2221
CityResponse response = dbReader.city(ipAddress);
23-
22+
2423
String countryName = response.getCountry().getName();
2524
String cityName = response.getCity().getName();
2625
String postal = response.getPostal().getCode();
2726
String state = response.getLeastSpecificSubdivision().getName();
28-
27+
2928
}
30-
29+
3130
}

0 commit comments

Comments
 (0)