Search code examples
javajsptitlepage-title

How to set the <title> dynamically in jsp page


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>

    }

Solution

  • 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