包含jsps编译错误

发布于 2024-10-19 12:58:11 字数 940 浏览 0 评论 0原文

有一个关于包含 jsp 头文件(使用 appengine)的正确方法的快速问题。我有一个 htmlinclude.jsp 只包含 head 部分

这是头文件

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

其他 jsp 文件包含此头文件,如下所示

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

在尝试部署到 appengine 时,出现错误 -

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

在本地计算机上运行它时,我没有任何问题...是否有我应该设置一个标志,以便 htmlinclude.jsp 不被编译?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猛虎独行 2024-10-26 12:58:11

我从来没有这样做过,但理论上你需要将其声明为全局变量而不是局部变量。您可以使用 <%! 来做到这一点%> 表达式。

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

不过,我猜想您依赖于 JSP 编译器/解析器,无论它是否接受它。


无论如何,这不是“正确的方式”。使用标签库和 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>

<jsp:include page="htmlinclude.jsp">
  <jsp:param name="title" value="page title" />
</jsp:include>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文