有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java包含来自动态属性值的文件

我有一个项目在Java中需要使用thgat

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

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

但是,我现在需要内容。jsp必须是动态的

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

所以,

<%@include file=myVariable %>

共 (2) 个答案

  1. # 1 楼答案

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

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

    <jsp:include page="${myVariable}" flush="true" />
    
  2. # 2 楼答案

    我在关闭标记后使用静态include来解决这个问题 所以它仍然是静态的,可以像分配字符串一样使用

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