1

Requests: Please only answer if you know implications in depth.

Related Question that I found help from: Nested expression in JSP/JSTL

I want to make my links, paths, and variables (for images, scripts, and other pages and includes) generic so that refactoring or changes file locations in future would make no big problems.

What I thought was to make:

variables.jsp:

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<c:set var="mainDir" value="${pageContext.request.contextPath}/view/jsp" />
<c:set var="resourcesDir" value="${mainDir}/resources" /> 

header.jsp

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@include file="variables.jsp" %>
<html>
   <head><title>${pageTitle}</title></head>

login.jsp

<c:set var="pageTitle" >
    <spring:message code="pageTitle.login" />
</c:set>
<%@include file="${mainDir}/common/header.jsp" %>

<body>...
...
...
<%@include file="${mainDir}/common/footer.jsp" %>

Please observe the includes and c:sets / c:outs with spring:messages.

What is the proper way to do what I want to (if my current strategy is not sane).

Community
  • 1
  • 1
Masood Ahmad
  • 731
  • 4
  • 15
  • 38
  • As to `` tag, just omit ``. This is JSP 1.x style. Since JSP 2.0 (over a decade old already), EL is natively supported in template. Surely you aren't using JSP 1.x anymore. As to Spring tag, no idea. – BalusC Aug 03 '13 at 02:01
  • @BalusC sorry i didnt got you. what do you suggest as an alternative then? (for As to tag, just omit .) how to print the variable then? – Masood Ahmad Aug 03 '13 at 02:04
  • You don't need to use `` to get `${}` to work. This is only applicable in JSP 1.x/JSTL 1.0. Since JSP 2.0, just use ``. Your JSTL taglib URIs are from JSTL 1.1/1.2 which suggests that you're already on at least JSP 2.0. – BalusC Aug 03 '13 at 02:05
  • ok. i will edit my post to reflect that. but other than that the problems stated at bottom. e.g `" />` are not fixed – Masood Ahmad Aug 03 '13 at 02:06
  • As said, I have no idea. I'm no Spring user nor am I interested in using it. – BalusC Aug 03 '13 at 02:07
  • Thanks! but Its a general question on how to "` etc – Masood Ahmad Aug 03 '13 at 02:09
  • Looks like `` has just a `var` attribute like as JSTL's own ``: http://static.springsource.org/spring/docs/1.2.x/taglib/tag/MessageTag.html This way you don't need the whole `` around it at all. – BalusC Aug 03 '13 at 02:16
  • updated my question. Thanks uptil here! – Masood Ahmad Aug 03 '13 at 02:37

0 Answers0