How to set the <title> dynamically in jsp page

Jatin Gupta picture Jatin Gupta · May 31, 2016 · Viewed 7.4k times · Source

while launching a jsp page, I want to display the 'edition type' at the top of the browser window/ tab if page launched in 'teacher edition type'. There are 3 types of editions available in DB table, these are - teacher, student & common. In my JSP code, I am trying to set & trying to fetch 'edition type' from java action class. but, unable to do so.

Can anyone please guide how to get the Edition type in a JSP page

JSP code -

<% String printEditionTyp = (String)request.getAttribute("bookEditionID"); %>

<title>Message - <%out.print(printEditionTyp); %></title>

    }

Answer

Mahendra picture Mahendra · May 31, 2016

Make sure you are providing page-tile in header tag of html i.e. inside <head> tag.

Example:

<html>
    <head>
        <% Long printEditionTyp = (Long) request.getAttribute("bookEditionID"); %>
        <title>Message - <%= printEditionTyp %></title>
    </head>
<body>
...
...
</body>
</html>

EDIT: Typecasted bookEditionID to Long in place of String