java - spring mvc有没有全局变量?
怪我咯
怪我咯 2017-04-18 09:30:24
0
7
300

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()只能获取根目录。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(7)
小葫芦

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?

巴扎黑

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; 
黄舟

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

大家讲道理

Threadlocal can be tried

迷茫

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)

迷茫

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

PHPzhong

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template