I need to input URL like this http://localhost:8080/first
and after that my controller must go to http://localhost:8080/second
and so on until I came to http://localhost:8080/end
. Its something like recursion. At the end point I need to pring a list.
@Controller
@RequestMapping(value = "/", method = RequestMethod.GET)
public class CascadeController {
@RequestMapping("/first")
String first(ModelMap model) {
model.put("list", new ArrayList<String>());
return "/second";
}
@RequestMapping("/second")
String second(ModelMap model) {
((List) model.get("list")).add("A");
return "/third";
}
@RequestMapping("/third")
String third(ModelMap model) {
((List) model.get("list")).add("B");
return "end";
}
}
end.jsp
<%@ page import="java.util.List" %>
<html>
<body>
<%for(String s : (List<String>) request.getAttribute("list")){%>
<%=s%>
<%}%>
</body>
</html>
Is anybody can explain what is wrong with my code?