开发者

include jsps compilation error

开发者 https://www.devze.com 2023-02-14 00:16 出处:网络
Had a quick question on the right way to include jsp header files (using appengine). I have an htmlinclude.jspthat just contains the head portion

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%></t开发者_C百科itle>
</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?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号