我需要輸入這樣的網址http://localhost:8080/first
,之後我的控制器必須去http://localhost:8080/second
等等,直到我來到http://localhost:8080/end
。它像遞歸一樣。最後,我需要列出一個列表。如何建立級聯控制器?
@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>
是任何人都可以解釋什麼是錯我的代碼?
你得到什麼結果,它是如何與你的期望有什麼不同? –
您是否聽說過Spring Web Flow?也許有用.. – gipinani
我不能使用Spring WF,只能使用MVC。 – user3163426