I am new to JSPs and am actually a core java programmer. I have a
problem. I have different jsp files and all these jsp files should be
including a header.jsp. I want to display different title in this
header.jsp for each of the above files, I mentioned. The way I thought
was that I'll have a variable called pageTitle in all the above jsp
files and access this variable in header.jsp. But I am not successful
uptil now.
Manish Pandit - 09 Oct 2006 21:39 GMT
Hi,
Looks like JSP tag files might be your best bet. They are kind of like
include, but can handle attributes. If all you have to do is change the
title, it can be passed as an attribute to the tag file. If you want to
add more customization, you might have to consider using tag handlers -
they can contain complex java code.
http://today.java.net/pub/a/today/2003/11/14/tagfiles.html
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags5.html
-cheers,
Manish
Arne Vajhøj - 10 Oct 2006 00:36 GMT
> I am new to JSPs and am actually a core java programmer. I have a
> problem. I have different jsp files and all these jsp files should be
[quoted text clipped - 3 lines]
> files and access this variable in header.jsp. But I am not successful
> uptil now.
page.jsp
<%
String pagename = "example page";
%>
<%@ include file="hdr.jsp" %>
Bla bla bla
hdr.jsp
I am <%=pagename%>.
<hr>
works here.
I do not believe that you can do it with the jsp:include
tag.
And in general I think you are on the wrong track - this is
not the JSP way of doing things.
Arne
anubhakhurana@gmail.com - 10 Oct 2006 16:28 GMT
Thanks to all who replied. This was of great help and got many other
pointers too through your replies. Thanks a ton.
Also Arne,
Can you please elaborate on what you exactly mean by "you are on the
wrong track - this is
not the JSP way of doing things". This might help me to have a
different point of view.
-Anubha
> page.jsp
>
[quoted text clipped - 18 lines]
>
> Arne
Arne Vajhøj - 11 Oct 2006 00:34 GMT
> Can you please elaborate on what you exactly mean by "you are on the
> wrong track - this is
> not the JSP way of doing things". This might help me to have a
> different point of view.
You should be looking at:
- having requests going to a controller servlet
that sets various info in request and forward
to a JSP page
- having no embedded Java code in the JSP code
and only using taglibs
etc.etc.
Arne
Chris - 10 Oct 2006 00:37 GMT
> I am new to JSPs and am actually a core java programmer. I have a
> problem. I have different jsp files and all these jsp files should be
[quoted text clipped - 3 lines]
> files and access this variable in header.jsp. But I am not successful
> uptil now.
myjsp.jsp:
<html>
<%
String title = "A Title";
%>
<%@ include file = "includes/header.jsp" %>
Rest of the page here
</html>
Reference <%=title%> in your header.jsp. You can set title to a
different value in each page that includes the header.
Kristian Lier Selnæs - 10 Oct 2006 07:26 GMT
You could check out something like Struts tiles as well,
http://struts.apache.org/1.x/struts-tiles/index.html (not tied to Struts
btw).
-Kristian
> I am new to JSPs and am actually a core java programmer. I have a
> problem. I have different jsp files and all these jsp files should be
[quoted text clipped - 3 lines]
> files and access this variable in header.jsp. But I am not successful
> uptil now.
Manish Pandit - 11 Oct 2006 02:13 GMT
Another way to do it is with jsp:include
In parent.jsp, do this:
<jsp:include file='header.jsp>
<jsp:param name="title" value="some text"/>
</jsp:include>
In header.jsp, do this:
Title is ${param.title}.
-cheers,
Manish
Manish Pandit - 11 Oct 2006 02:15 GMT
> <jsp:include file='header.jsp>
sorry - please read <jsp:include page="header.jsp">
-cheers,
Manish