0

I wanted to make a navbar with a dynamically changing title, depending on the page who is including it

The code in the navbar.jsp is :

<li><a><label class="control-label" style="font-size:24px; 
font-family:'Calibri'">| ${param.title}</label></a></li>

And the code in, for example, summary.jsp would be like

<jsp:include page="navbar.jsp">
<jsp:param name="title" value="Summary"/>
</jsp:include>

It works fine when I load it in my workspace (Eclipse Mars, JDK 1.8, Tomcat 8) It worked once on my team mate workspace (Eclipse Mars, JDK 1.7, Tomcat 6), and then it didn't

All you can read on the navbar instead of the title when you load summary.jsp is ${param.title} I read the other posts, I tried the second method that I found here :

<%= request.getAttribute("title") %>

in navbar.jsp, and then (in summary.jsp)

<% request.setAttribute("title", "Summary"); %>

But as a result I only had a null instead !

What could be the problem ?

Koblenz
  • 139
  • 1
  • 6
  • No one can answer ? (if I don't find the answer here... ) – Koblenz Feb 20 '16 at 16:08
  • Are you sure the code `<% request.setAttribute("title", "Summary"); %>` is in front of ``? If not, it work as expected. – Beck Yang Feb 23 '16 at 15:54
  • @beckyang Yeah, it was ! then I tried with `<%@ include... %>` instead of `` and it didn't work. Finally I resolved this problem by changing the scope from "request" to "session". But then I noticed another bug : the attribute would sometimes keep the title of the last page (so you have pages with the wrong titles) As a conclusion, I have to understand why the first method (with jsp : param) didn't work (plus the second method is deprecated) – Koblenz Feb 29 '16 at 10:53
  • **${param.title}** is equal to `<%= request.getParameter("title")%>`. The `` is used add a request **parameter**, and it can only be read by the included JSP. The correct [Expression Language](http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html) for get request attribute **title** is `${requestScope.title}` or `${title}`. – Beck Yang Mar 02 '16 at 05:50
  • As I tried to explain,the fact is not that the method _didn't work at all_, it worked on my environnement (Tomcat 8, JDK 1.8) with `${param.title}`, but not on my colleague environment (Tomcat 6, JDK 1.7) So IMO it's rather a problem of some jar file or something else ! I'll try your solution anyway ! – Koblenz Mar 06 '16 at 10:41

0 Answers0