要使用我的静态文件(CSS,JS),我必须编写绝对路径/AppName/templates/style/main.css.有什么解决方案,我可以写相对路径style/main.css吗?
我有这个结构:
WebContent
resources
components
top.xhtml
company
about_us.xhtml
index.xhtml
Run Code Online (Sandbox Code Playgroud)
top.xhtml是一个组件,即在使用index.xthml与about_us.xhtml太.
top.xhtml
<ul>
<li><a href="index.xhtml">Home</a></li>
<li><a href="company/about_us.xhtml">About us</a></li>
...
</ul>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,当当前页面是index.xhtml组件正确生成URL时,但当当前页面时about_us.xhtml,它会生成错误的URL.我不能使用相对路径,因为它也会生成错误的URL.我认为这是因为组件基于*.xhtml页面的当前路径.
我能找到的唯一解决方案是:
<ul>
<li><a href="${pageContext.request.contextPath}/webname/index.xhtml">Home</a></li>
<li><a href="${pageContext.request.contextPath}/webname/about_us.xhtml">About us</a></li>
...
</ul>
Run Code Online (Sandbox Code Playgroud)
但我认为根本不是"优雅".有任何想法吗?
我在Servlet容器(端口8080)上运行WebApplication,该环境可以从Internet(外部)和公司内部(内部)访问,例如
http://external.foo.bar/MyApplication
http://internal.foo.bar/MyApplication
Run Code Online (Sandbox Code Playgroud)
使用带有mod_proxy的apache http服务器将incomming(外部/内部)请求重定向到servlet容器.配置如下所示:
ProxyPass /MyApplication http://localhost:8080/MyApplication retry=1 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse /MyApplication http://localhost:8080/MyApplication
Run Code Online (Sandbox Code Playgroud)
我现在面临的问题是某些MyApplication响应依赖于原始请求URL.具体:将为WSDL文档提供具有元素的schemaLocation="<RequestUrl>?xsd=MyApplication.xsd"元素.
使用我当前的配置,它总是看起来像
<xs:import namespace="..." schemaLocation="http://localhost:8080/MyApplication?xsd=MyApplication.xsd"/>
Run Code Online (Sandbox Code Playgroud)
但它应该是
External Request: <xs:import namespace="..." schemaLocation="http://external.foo.bar/MyApplication?xsd=MyApplication.xsd"/>
Internal Request: <xs:import namespace="..." schemaLocation="http://internal.foo.bar/MyApplication?xsd=MyApplication.xsd"/>
Run Code Online (Sandbox Code Playgroud)
我想这是一个常见的要求.但由于我不是apache http服务器及其模块配置的专家,如果有人可以提供一些(详细的)帮助,我会很高兴.
提前致谢!
使用给定的应用程序
@ApplicationPath("/api")
public class MyApplication {
}
Run Code Online (Sandbox Code Playgroud)
UriInfo#getBaseUri给了我一个应用程序路径。
@Context
private UriInfo uriInfo
uriInfo.getBaseUri(); // http://address/<context-path>/api
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得上下文路径?
如何获取上下文路径的完整 URL?
http://address/<context-path>
Run Code Online (Sandbox Code Playgroud)
更新
我目前使用这个答案中的代码。
@Context
private HttpServletRequest servletRequest;
final URI contextUri
= URI.create(servletRequest.getRequestURL().toString())
.resolve(servletRequest.getContextPath());
Run Code Online (Sandbox Code Playgroud)
还有其他建议吗?