I’m starting building web apps in Spring 3 (and in J2EE) in general.
Looking at the petclinic example I’ve seen that the programmer creates many JSP pieces, like header, includes, footer and then stitches them together using static inclusion. Anyway what I’d like is that I may have a base page, like Base.jsp and be able to include things like this:
<body>
<jsp:include page="${subpage}"></jsp:include>
</body>
the reason is that I’d like a main page, then being able to put in the ModelAndView returned by the controller which parts of the pages display in each situation (with the data attached to it). This works, but it gives no errors in case ${subpage} is not found, the jsp name is wrong or missing. I’d like more error checking…
Is this the best and recommended way to do this? And if this seems a good idea for what I’ve in mind, what’s the correct way of doing it?
It appears you have additional quotes in your
subpage. Get rid of them. For example:If you have to set it in a controller or servlet – just use
request.setAttribute("subpage", "/jsp/index.jsp")