在jsp和java之间重用变量名(Spring)

时间:2017-06-19 13:38:34

标签: java html spring jsp jstl

我现有的jsp是

eval

我现有的Spring Java是

<c:forEach var="domainOrGroupParentDetails"
    items="${allDomainOrGroupParentDetails}" varStatus="status">
    <option
        value="${domainOrGroupParentDetails.domainOrGroupParentPojo.name}">
        ${domainOrGroupParentDetails.domainOrGroupParentPojo.name}</option>
</c:forEach>

this开始,我尝试执行以下操作

data.put("allDomainOrGroupParentDetails",
    getDomainOrGroupParentResponse.getDomainOrGroupParentPojoWrappers());

在jsp中我做了

public class ModelObjectKeys {
    public static class OnLoadAddDriverConstants {

    }
    public static final String allDomainOrGroupParentDetails = "allDomainOrGroupParentDetails";
}

我还在html中导入了这个

的java文件
<c:forEach var="domainOrGroupParentDetails"
    items="${<%=ModelObjectKeys.allDomainOrGroupParentDetails%>}" varStatus="status">
    <option
        value="${domainOrGroupParentDetails.domainOrGroupParentPojo.name}">
        ${domainOrGroupParentDetails.domainOrGroupParentPojo.name}</option>
</c:forEach>

仍然不起作用。我得到了

  

org.apache.jasper.JasperException:   /WEB-INF/views/onLoadAddDriverView.jsp(第270行,第10列)   “$ {&lt;%= ModelObjectKeys.allDomainOrGroupParentDetails%&gt;}”包含   表达无效

我错过了什么?

修改

<%@ page import="com.mnox.corporate.model.design.ModelObjectKeys"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

2 个答案:

答案 0 :(得分:0)

更改items="${<%=ModelObjectKeys.allDomainOrGroupParentDetails%>}"items="${ModelObjectKeys.allDomainOrGroupParentDetails}"

您无法在EL表达式中嵌套脚本

答案 1 :(得分:-1)

${<%=ModelObjectKeys.allDomainOrGroupParentDetails%>}应该像${ModelObjectKeys.allDomainOrGroupParentDetails}