文件包含不起作用

发布于 2024-12-22 20:38:51 字数 530 浏览 2 评论 0原文

以下代码在 Netbeans 中引发错误,指出 include 语句未关闭。我尝试过一些类似 @%> 的方法,但我无法弄清楚发生了什么。我在这里做错了什么?

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><%=request.getAttribute("title")%></title>
    </head>
    <body>
        <%@include file=request.getAttribute("template")%>
    </body>
</html>

The below code throws an error in Netbeans saying the include statement is not closed. I've tried a few things like @%> and I'm not able to figure out what's up. what am I doing wrong here?

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><%=request.getAttribute("title")%></title>
    </head>
    <body>
        <%@include file=request.getAttribute("template")%>
    </body>
</html>

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

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

发布评论

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

评论(2

柏拉图鍀咏恒 2024-12-29 20:38:51

尝试使用 >

<jsp:directive.include file="<%= request.getAttribute("template") %>"/>

根据模板的内容, 也可能有效:

<jsp:include path="<%= request.getAttribute("template") %>"/>

Try using <jsp:directive.include/>:

<jsp:directive.include file="<%= request.getAttribute("template") %>"/>

Depending on the contents of your template, <jsp:include/> may also work:

<jsp:include path="<%= request.getAttribute("template") %>"/>
失而复得 2024-12-29 20:38:51

include 指令在编译时(翻译时)工作,文件中列出的路径应该相对于 Web 应用程序。

翻译 JSP 页面时处理 include 指令
到 servlet 类中。该指令的作用是插入
另一个文件中包含的文本——静态内容或另一个 JSP
页面--包含JSP页面中

如果想使用更灵活的东西来包含文件时使用jstl标签 < c:导入>

使用 jstl 我们还可以包含这些内容或文件
它们不是当前网络应用程序的一部分,而是在撒谎
Web 应用程序之外的某个地方

The include directive works at compile time (translation time), the path listed in file should be relative to the web application.

The include directive is processed when the JSP page is translated
into a servlet class. The effect of the directive is to insert the
text contained in another file--either static content or another JSP
page--in the including JSP page

if you want to use something more flexible when used to include files jstl tag < c:import >

Using the jstl we can also include those contents or files
which are not a part of the current web application but lying
somewhere outside the web application

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