Below is my controller:
@RequestMapping("Student/{ID}/{Name}/{Age}")
public void addStudent(@PathVariable String ID,
@PathVariable String Name,
@PathVariable String Age,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
try {
// Handling some type errors
new Integer(Age); // Examine the format of age
StatusBean bean = new StatusBean();
bean.setResonCode("000"); // Success/Fail reasons
bean.setStatus("1"); // 1: Success; 0: Fail
outputJson(bean, response);
}
catch (NumberFormatException e) {
...
}
catch (Exception e) {
...
}
Student's ID, Name, Age are inputted by users,and these variables could not be null or blank space.
In normal case, the controller can handle http://localhost:8080/Student/003/Peter/17
.
However, it could not handle the cases such as http://localhost:8080/Student///17
or http://localhost:8080/Student/003/Peter/
. How could I do if I want to handle these cases in my controller?
Another question is, new Integer(Age) is a good way to examine the format?