문제

on header include file:

<head>
    <title>${pageTitle}</title>
</head>

test page:

<% String pageTitle = "Test Title"; %>

<jsp:include page="includes/header.jsp" />

I am trying to declare the page title on the test page and use the value of that variable in the title tag of my header include. This doesn't seem to be working.

Can anybody help me out?

도움이 되었습니까?

해결책 2

Test.jsp

<% String pageTitle = "Test Title"; %>
<jsp:include page="header.jsp">
    <jsp:param name="pageTitle" value="<%=pageTitle%>"/>
</jsp:include>

header.jsp

To get the passing value you need to use param EL

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${param.pageTitle}</title>
               <!--Need to use param EL-->
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>

다른 팁

It can be done by

    <jsp:include page="includes/header.jsp">
       <jsp:param name="pageTitle" value="value-here"/>
    </jsp:include>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top