Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SpringMVC中使用HTML/JavaScript文件中的属性变量_Spring_Spring Mvc - Fatal编程技术网

在SpringMVC中使用HTML/JavaScript文件中的属性变量

在SpringMVC中使用HTML/JavaScript文件中的属性变量,spring,spring-mvc,Spring,Spring Mvc,我正在研究SpringMVC3.x。我们可以在HTML/JavaScript文件中使用属性文件内容吗 我在类路径中有一个名为webMessages.properties的属性文件 而且Spring-servlet.xml已经 <context:property-placeholder location="classpath:/jdbc.properties,classpath:/webMessages.properties" /> 当我尝试访问JavaScript文件中的属性时

我正在研究SpringMVC3.x。我们可以在HTML/JavaScript文件中使用属性文件内容吗

我在类路径中有一个名为webMessages.properties的属性文件

而且Spring-servlet.xml已经

<context:property-placeholder location="classpath:/jdbc.properties,classpath:/webMessages.properties" />

当我尝试访问JavaScript文件中的属性时,它不会给出任何输出:

<p>"${topPath.topHeading}"</p>
“${topPath.topHeading}”


如果这是可能的,请告知?

您正在尝试的操作是可能的,但文件需要是JSP。在JSP内部,请尝试以下操作:

${properties['topPath.topHeading']}

我不确定context:property占位符是否会公开定义之外的属性。但我可以通过以下方式获得:

    <bean id="propertyPlaceHolderConfigurer" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath:/jdbc.properties</value>
                <value>classpath:/webMessages.properties</value>
            </list>
        </property>
    </bean>

    <context:property-placeholder
        properties-ref="propertyPlaceHolderConfigurer"
        ignore-resource-not-found="true"/>

类路径:/jdbc.properties
类路径:/webMessages.properties
在jsp中: 包括此标签:

    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

然后通过以下方式访问该属性:

    <spring:eval expression="@propertyPlaceHolderConfigurer.getProperty('topPath.topHeading')" />


您看到了吗?您使用的是什么视图解析器?JSP?速度免费标记?还有别的吗?我甚至试过了。。但没有输出。我得到了以下错误:
org.springframework.expression.spel.SpelEvaluationException:EL1004E:(pos 20):在org.springframework.beans.factory.config.PropertyPlaceholderConfigurer type上找不到方法调用:Method getProperty(java.lang.String)。在我的
\spring-beans-4.1.5.RELEASE.jar中,我没有看到这个方法。