Include file from dynamic property value

青春壹個敷衍的年華 提交于 2019-12-28 13:22:33

问题


I have a project in Java thgat needs to use;

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

to include a file into the current jsp page.

However, I now need the content.jsp to be dynamic.

How can I substitute everything in the quotes with a variable?

So;

<%@include file=myVariable %>

回答1:


Instead of using static include, you can use dynamic include, then you can do something like this:-

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

or

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



回答2:


i have work around by using the static include after closing the tag so it still static and can be used as if you assign a string

        <% 

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

        %>


来源:https://stackoverflow.com/questions/4988086/include-file-from-dynamic-property-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!