AreaCheckServlet extra null check for parameters

This commit is contained in:
Egor 2023-02-18 14:50:59 +03:00
parent 965fac1acb
commit b0e380f094
2 changed files with 19 additions and 3 deletions

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -31,11 +31,21 @@ public class AreaCheckServlet extends HttpServlet {
timezoneOffset = 0; timezoneOffset = 0;
} }
String xParam = req.getParameter("xValue"), yParam = req.getParameter("yValue"),
rParam = req.getParameter("rValue");
if (xParam == null || yParam == null || rParam == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "X, Y or R is not defined");
RequestDispatcher rootDispatcher = req.getRequestDispatcher("/");
rootDispatcher.forward(req, resp);
return;
}
float x, y, r; float x, y, r;
try { try {
x = Float.parseFloat(req.getParameter("xValue"));
y = Float.parseFloat(req.getParameter("yValue")); x = Float.parseFloat(xParam);
r = Float.parseFloat(req.getParameter("rValue")); y = Float.parseFloat(yParam);
r = Float.parseFloat(rParam);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "X, Y and R must be numeric"); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "X, Y and R must be numeric");
RequestDispatcher rootDispatcher = req.getRequestDispatcher("/"); RequestDispatcher rootDispatcher = req.getRequestDispatcher("/");