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;
}
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;
try {
x = Float.parseFloat(req.getParameter("xValue"));
y = Float.parseFloat(req.getParameter("yValue"));
r = Float.parseFloat(req.getParameter("rValue"));
x = Float.parseFloat(xParam);
y = Float.parseFloat(yParam);
r = Float.parseFloat(rParam);
} catch (NumberFormatException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "X, Y and R must be numeric");
RequestDispatcher rootDispatcher = req.getRequestDispatcher("/");