Jersey 在资源方法中获取当前应用程序路径值

Jersey 在资源方法中获取当前应用程序路径值,jersey,Jersey,我有一个jersey 2.0应用程序,使用带有freemarker模板的mcv。在一个模板中,我有一个表单,其操作是重新提交到同一个url。假设表单url为: http://my-domain.com/app-base-path/my-form 因此,应用程序注释为:@ApplicationPath(“应用程序基本路径”) 资源路径注释是@path(“我的表单”)。太好了 我正在尝试将表单操作动态设置为: <form name="settings" action="${model.fo

我有一个jersey 2.0应用程序,使用带有freemarker模板的mcv。在一个模板中,我有一个表单,其操作是重新提交到同一个url。假设表单url为:

http://my-domain.com/app-base-path/my-form 
因此,应用程序注释为:
@ApplicationPath(“应用程序基本路径”)
资源路径注释是
@path(“我的表单”)
。太好了

我正在尝试将表单操作动态设置为:

<form name="settings" action="${model.formAction}" method="post">
如何检索包括应用程序基本路径在内的路径?
请不要用javascript

您可以使用
uriInfo.getAbsolutePath()
获取绝对URI,它将返回带有相应资源方法的完整URI的
URI

http://localhost:8080/app-base-path/myform
URI可以分解为不同的部分,
URI
类有特定的方法来获取这些部分

scheme            authority              path
--------------------------------------------------------
http    ://     localhost:8080     /app-base-path/myform
URI类具有获取所有这些内容的方法

uri.getScheme()
uri.getAuthority()
uri.getPath()

我很确定我不需要告诉你你想要哪一个:-)

作为旁白,为了回答标题问题,如果你只想要应用程序路径,你可以使用
UriInfo.getBaseUri().getPath()
我可能已经过度简化了它。我的本地dev tomcat托管了几个web应用程序,每个应用程序都有一个基本上下文路径。比如:localhost/app name/app base path/my form。我只需要与应用程序名称相关的部分。
UriBuilder.fromPath(uriInfo.getBaseUri().getPath()).path(FormResource.class).build().toString()
。。应该使用workr
uriInfo.getBaseUriBuilder().path(FormResource.class.build()
uri.getScheme()
uri.getAuthority()
uri.getPath()