如何在带有Spring的外部javascript文件中使用JSP变量

时间:2018-07-31 00:36:57

标签: javascript jsp servlets

我的javascript中包含JSP变量,例如AJAX调用网址的示例

url: "${pageContext.request.contextPath}/darf/${assignment.ffaWholeId}",

据我所知,实际上是在项目中将javascript文件创建为.jsp文件,并将darf-js.jsp放入了WEB-INF/views/js文件夹中。我不确定如何从父jsp darf.jsp引用它。我尝试了以下

<script src="${pageContext.request.contextPath}/js/darf-js.jsp"></script>
<script src="${pageContext.request.contextPath}/darf-js.jsp"></script>
<script src="${pageContext.request.contextPath}/views/js/darf-js.jsp</script>

我的视图解析器

<beans:bean id="tilesViewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <beans:property name="viewClass">
        <beans:value>org.springframework.web.servlet.view.tiles3.TilesView
        </beans:value>
    </beans:property>
    <beans:property name="order">
        <beans:value>1</beans:value>
    </beans:property>
</beans:bean>

<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix">
        <beans:value>/WEB-INF/views/</beans:value>
    </beans:property>
    <beans:property name="suffix">
        <beans:value>.jsp</beans:value>
    </beans:property>
    <beans:property name="order">
        <beans:value>#{tilesViewResolver.order+1}</beans:value>
    </beans:property>
</beans:bean>

<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix">
        <beans:value>/WEB-INF/views/js</beans:value>
    </beans:property>
    <beans:property name="suffix">
        <beans:value>.jsp</beans:value>
    </beans:property>
    <beans:property name="order">
        <beans:value>#{tilesViewResolver.order+2}</beans:value>
    </beans:property>
</beans:bean>

0 个答案:

没有答案