[英]How to get rewritten url
When I deploy my app (.war) at tomcat I get directory in webapps named like 'myapp-0.0.1-SNAPSHOT' this app I redirect by AJP当我在 tomcat 部署我的应用程序(.war)时,我在名为“myapp-0.0.1-SNAPSHOT”的 webapps 中获得目录,这个应用程序我通过 AJP 重定向
server.xml (partial) server.xml(部分)
<Connector protocol="AJP/1.3" address="::1" port="8009"
redirectPort="8443" secretRequired="false" />
in Httpd apache I use the following code httpd.conf (partial)在 Httpd apache 我使用下面的代码 httpd.conf(部分)
<Location /myapp>
ProxyPass ajp://localhost:8009/myapp-app-0.0.1-SNAPSHOT
</Location>
For creating download url in my app I'm using为了在我正在使用的应用程序中创建下载 url
final String baseUrl =
ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString();
when I start app on test I get url like当我在测试中启动应用程序时,我得到 url 之类的
for web http://192.168.10.1.85/
对于 web http://192.168.10.1.85/
for downloading http://192.168.10.1:85/files/PRN1/001234/firmware/file.zip
(this link generated based on data from database and it is dynamically)用于下载http://192.168.10.1:85/files/PRN1/001234/firmware/file.zip
(此链接是根据数据库中的数据生成的,它是动态的)
Ok.行。 it's good I see all correctly.还好我没看错。
When I open httpd link in web http://192.168.10.1/myapp
- ok it's correct当我在 web http://192.168.10.1/myapp
中打开 httpd 链接时 - 好的,这是正确的
but for my dynamic link I get incorrect context path http://192.168.10.1/myapp-0.0.1-SNAPSHOT/files/PRN1/001234/firmware/file.zip
- it's not correct and my app couldn't provide data from this link但是对于我的动态链接,我得到了不正确的上下文路径http://192.168.10.1/myapp-0.0.1-SNAPSHOT/files/PRN1/001234/firmware/file.zip
- 这是不正确的,我的应用程序无法提供数据这个链接
good link http://192.168.10.1/myapp/files/PRN1/001234/firmware/file.zip
好的链接http://192.168.10.1/myapp/files/PRN1/001234/firmware/file.zip
How to correct describe baseUrl?如何正确描述 baseUrl? Or I should add data about Location some in configuration?或者我应该在配置中添加一些关于 Location 的数据?
As far as I understand, from Database "files/PRN1/001234/firmware/file.zip" this path generated dynamically and then you combine your web application's address with this path.据我了解,从数据库“files/PRN1/001234/firmware/file.zip”动态生成这条路径,然后将 web 应用程序的地址与这条路径结合起来。
Then you can use below url generation method in java那么就可以在java中使用下面的url生成方法
String protocol = "http";
String host = "192.168.10.1";
int port = 8080;
String path = "/myapp/files/PRN1/001234/firmware/file.zip";
String auth = null;
String fragment = null;
URI uri = new URI(protocol, auth, host, port, path, query, fragment);
URL url = uri.toURL();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.