包含动态属性值的文件

时间:2011-02-14 01:15:48

标签: java jsp jspinclude

我有一个Java thgat需要使用的项目;

<%@include file="content.jsp" %>

将文件包含到当前的jsp页面中。

但是,我现在需要content.jsp是动态的。

如何用变量替换引号中的所有内容?

因此;

<%@include file=myVariable %>

2 个答案:

答案 0 :(得分:36)

您可以使用动态包含,而不是使用静态包含,然后您可以执行以下操作: -

<jsp:include page="<%= myVariable %>" flush="true" />

<jsp:include page="${myVariable}" flush="true" />

答案 1 :(得分:3)

我在关闭标签后使用静态包含工作 所以它仍然是静态的,可以像分配字符串一样使用

        <% 

            switch(questionType){

                case 1:%><%@include file="qtypes/yesNo.jspf"%><%
                break; 
                case 5:%><%@include file="qtypes/eval.jspf"%><%
                break; 
                default :%><%@include file="qtypes/yesNo.jspf"%><%
                break; 
            } 

        %>