Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring and dynamic inclusion of JSP files

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?

like image 357
gotch4 Avatar asked Jan 24 '11 11:01

gotch4


People also ask

Can I use JSP in spring boot?

When building Web Applications, JavaServer Pages (JSP) is one option we can use as a templating mechanism for our HTML pages. On the other hand, Spring Boot is a popular framework we can use to bootstrap our Web Application.

Do we use JSP in spring?

In short: Both technologies are used in creating an application, Spring provides the flow, and JSP provides the way we represent our web page.

Can JSP generate dynamic pages?

Just like JSP pages, JSP documents can generate dynamic content using expressions language (EL) expressions, scripting elements, standard actions, and custom tags.


1 Answers

You might want to use Apache Tiles 2 integration for managing your JSP files. Spring has good integration support Apache Tiles. It also shows if there's an error in your page. I've put an example of it at http://krams915.blogspot.com/2010/12/spring-mvc-3-tiles-2-integration.html

like image 174
chris Avatar answered Sep 28 '22 15:09

chris