Spring MVC - JSP - Place to Store Environment Specific Constants

后端 未结 1 1368
太阳男子
太阳男子 2021-01-05 10:58

Where in the Spring-MVC/JSP application would you store things that need to be accessed by both the controllers and views such as environment specific base_url\'s, applicati

相关标签:
1条回答
  • 2021-01-05 11:26

    What is scope="application"? That's a new one to me.

    Anyway, if all you need is for your JSPs to be able to access Spring beans, then you can expose the beans to JSTL using the exposedContextBeanNames property of InternalResourceViewResolver. For example:

    <bean id="myEnv" class="com.myapp.MyAppEnvironment">
        <property name="baseUrl" value="http://localhost:8080/myapp/"/>
        <property name="videoPlayerId" value="234346565"/>
    </bean>
    
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="exposedContextBeanNames">
          <list>
             <value>myEnv</value>
          </list>
       </property>
    </bean>
    

    and then in your JSP:

     ${myEnv.baseUrl}
    
    0 讨论(0)
提交回复
热议问题