Home  >  Q&A  >  body text

java - spring mvc有没有全局变量?

spring mvc当中有没有全局变量,类似我设置项目的路径base = "/rs" 或者base="http://192.168.0.1/rs"
然后在页面使用el表达式获取${base} 引入js或者css

因为网站部署在内网的机器如192.168.1.1 tomcat根目录 外网访问只能通过61.11.11.11:1002/project 这样进行访问,request.getContextPath()只能获取根目录。

怪我咯怪我咯2765 days ago296

reply all(7)I'll reply

  • 高洛峰

    高洛峰2017-04-18 09:32:24

    Is this how to access the intranethttp://192.168.1.1/rs,外网是这么访问的:http://61.11.11.11:1002/project/rs?

    I don’t quite understand the issue of reverse proxy, but wouldn’t it be enough if you make the paths for the internal and external networks the same?

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:32:24

    Create a new configure.properties file under the classpath with the following content:

    web.base=root   

    Then configure the following xml fragment in spring-mvc-servlet.xml. Note that it must be in the spring mvc configuration file.

    <bean  
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
            <list>  
                <value>classpath:configure.properties</value>  
            </list>  
        </property>  
    </bean>  

    Then use @Value in the controller to inject the configured value

        @Value("${web.base}")  
        private String base; 

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:32:24

    This has nothing to do with the global situation. This value should be obtained by yourself, not set by you,

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:32:24

    Threadlocal can be tried

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:32:24

    Write a configuration file specifically to store all the global variables you need, and construct a method to dynamically read the configuration, which can be directly introduced by the frontend. (an idea)

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:32:24

    Spring itself can configure similar global variables in xml, such as configuring fixed variables in ./application.propertites and then reading them

    Your problem should be related to the forwarding of URL mapping from the internal network to the external network. Configure it on the public network machine

    reply
    0
  • PHPz

    PHPz2017-04-18 09:32:24

    In the final analysis, it is caused by the name of the project, so just leave the project as it iswebApps->ROOT 下 文件夹名字大写,就不需要项目名了。
    引入css以及js直接 就 / Okay

    reply
    0
  • Cancelreply