0

Had a quick question on the right way to include jsp header files (using appengine). I have an htmlinclude.jsp that just contains the head portion

This is the header file

<html>
<head> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/styles.css" />     
<title><%=title%></title>
</head>
<body>     

Other jsp files include this headerfile as follows

<% String title="page title" ;%>
<%@ include file="htmlinclude.jsp" %>'

While trying to deploy to appengine I get an error -

SEVERE: Error compiling file: htmlinclude_jsp.java     
[javac] Compiling 1 source file
[javac] C:\htmlinclude_jsp.java:46: cannot find symbol
[javac] symbol  : variable title
[javac] location: class org.apache.jsp.htmlinclude_jsp
[javac]       out.print(title);
[javac]                 ^
[javac] 1 error

While running it off of the local machine I have no issues...Is there a flag I should set so the htmlinclude.jsp is not compiled?

user529265
  • 820
  • 10
  • 27

1 Answers1

1

I've never done it like that, but in theory you need to declare it as global variable rather than as local variable. You can do that with <%! %> expression.

<%! String title = "page title"; %>

I however guess that you're dependent on the JSP compiler/parser whether it eats that or not.


Regardless, this is not the "right way". Use taglibs and EL.

<html>
  <head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="/styles.css" />     
    <title>${param.title}</title>
  </head>
  <body>

with

<jsp:include page="htmlinclude.jsp">
  <jsp:param name="title" value="page title" />
</jsp:include>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555