File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Variable inside title tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Variable inside title tag" Watch "Variable inside title tag" New topic

Variable inside title tag

Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150

How can I get a variable inside I would like the title bar?

For example, the source of this page contains <TITLE>JavaRanch Big Moose Saloon</TITLE>.

I would like to use <TITLE>variableName</TITLE> where variableName is filled by the java bean prior to the browser display.

Thank You in Advance for Your Help,

sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
If u r using tiles u can make this a part of ur lay out and give a dynalmic value at the run time and u can retrive in ur jsp using tiles:getAsString tag

R its just a mtter of jsp and scriplets u use .If u had populated that in a bean ( better set it in the request ) so in ur jsp in scriplets u can directly say req.getAttribute of thatname

seems this is what u r asking for
Greg Martin

Joined: May 13, 2004
Posts: 1
You could just use regular JSP syntax:

String someVar = "";
<title><%= someVar %></title>

or, with the struts tags, you can store your titles in a properties file and use the message tage in the struts-bean tld.

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<html:base />

<title><bean:message key=""/></title>
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31781

If you want to do it in pure struts (without scriptlets) :


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
Thanks Jeanne!

<title><bean:write name="beanName" property="beanField"></title> is exactly what I needed.

Don't get me started about those stupid light bulbs.
subject: Variable inside title tag