Jsp在Spring MVC中包含带有Variable FileName的文件指令

时间:2015-03-23 18:57:56

标签: java jsp include

我在spring mvc应用程序中使用ModelAndView对象传递了文件名。但我无法修复此编译问题。我是WEB-Development的新手。

以下是我的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>).

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

您不应使用&lt;%@ include file =&#34;&lt;%= pageRed%&gt;&#34; %GT;

可以代替

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

这对我有用

祝你好运

答案 1 :(得分:0)

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

这样做的原因是什么?

相关问题