【问题标题】:Jsp Include File Directive with Variable FileName in Spring MVCJsp 在 Spring MVC 中包含带有变量 FileName 的文件指令
【发布时间】:2015-05-26 21:55:15
【问题描述】:

我在 spring mvc 应用程序中使用 ModelAndView 对象传递了文件名。但我无法解决这个编译问题。我是 WEB 开发的新手。

以下是我的jsp页面的内容。

<% String pageRed = "static/" + (String)request.getAttribute("redPage"); %>
<%@ include file="<%=pageRed %>" %> 

包含文件行给出以下错误

Multiple annotations found at this line:
    - Start tag (<jsp:directive.include>) not closed properly, expected '>'.
    - A file value is required in this directive
    - Invalid location of text ("<%=pageRed %>" %) in tag 
     (<jsp:directive.include>).

有什么想法吗?

【问题讨论】:

    标签: java jsp include


    【解决方案1】:

    您不能这样做,因为 include 指令在 servlet 转换时间 期间被解析,而 (String)request.getAttribute("redPage"); 在运行时被解析。

    这样做的原因是什么?

    【讨论】:

      【解决方案2】:

      你不应该使用 " %>

      可以代替

      <jsp:include page="static/${redPage_name}.jsp" />
      

      这对我有用

      祝你好运

      【讨论】:

        猜你喜欢
        • 2019-05-18
        • 1970-01-01
        • 2013-05-11
        • 2011-12-18
        • 2017-02-04
        • 1970-01-01
        • 2017-08-17
        相关资源
        最近更新 更多