Search code examples
javajspinternationalizationjsp-tags

JSP includes tags for internationalization


I have this structure in my JSP (template.jsp):

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="language" value="es" scope="session"/>
<fmt:setBundle basename="com.myweb.i18n.text"/>

<html>
  <body>
     <fmt:message key='login.label.username'/>
     <jsp:include page='/home/header.jsp' flush='true'/>
     <jsp:include page='/home/body.jsp' flush='true'/>
     <jsp:include page='/home/footer.jsp' flush='true'/>
  </body>

</html>

The fmt:message line works well (print a text label). But if I write this line in header.jsp or any other jsp included does not work.

I must write all tag lib lines in all jsp files? There any way to include without repeat the firsts 4 lines in all my jsp?

Thanks!

Edit: example header.jsp

<div>
   <fmt:message key='login.label.username'/>
   <jsp:include page='/home/header-left.jsp' flush='true'/>
   <jsp:include page='/home/header-center.jsp' flush='true'/>
   <jsp:include page='/home/footer-right.jsp' flush='true'/>
</div>

Solution

  • put the lines in a jsp & include it in the current jsp i;e template.jsp as

    <@include file="path/jspcontaininglibs.jsp"/>
    <html>
      <body>
         <fmt:message key='login.label.username'/>
         <jsp:include page='/home/header.jsp' flush='true'/>
         <jsp:include page='/home/body.jsp' flush='true'/>
         <jsp:include page='/home/footer.jsp' flush='true'/>
      </body>
    </html>