JSF 中的 Java Web 服务 URL

标签 java web-services jsf

我创建了一个 JSF 应用程序,它也提供了一些 Web 服务。 Web 服务是通过注释创建的。

现在我想创建一个 webserviceInfo.xhtml 页面,从中获取所有需要的网络服务信息。

当我转到地址 http://our.server.com/application/OurWebserviceName 时,我获得了访问网络服务所需的所有信息(此信息页面由 Glassfish 自动生成) .

为了包含此页面,我在 webserviceInfo.xhtml 中执行了以下操作:

 <iframe scrolling="automatic"  width="971" height="1000" src="#{myBean.generateUrlToWebservice()}/OurWebserviceName"/>

地点:

public String generateUrlToWebservice(){
    FacesContext fc = FacesContext.getCurrentInstance();
    String servername = fc.getExternalContext().getRequestServerName();
    String port = String.valueOf(fc.getExternalContext().getRequestServerPort());
    String appname = fc.getExternalContext().getRequestContextPath();
    return "http://"+servername+":"+port+appname;
}

有没有更优雅的解决方案?

BR,雷内

最佳答案

使用页面相关 URL。

<iframe src="OurWebserviceName"></iframe>

或使用 <base>在 JSTL 的帮助下标记 functions标签库。

<html xmlns:fn="http://java.sun.com/jsp/jstl/functions">
...
<base href="#{fn:replace(request.requestURL, request.requestURI, '')}#{request.contextPath}"></base>

这样任何不以 scheme 或 / 开头的 URL始终与此 URL 相关。

或者,如果您真的需要在 JSF 中执行此操作,则以下方案和端口可以减少麻烦。

HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
return request.getRequestURL().toString().replace(request.getRequestURI, "") + request.getContextPath();

关于JSF 中的 Java Web 服务 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4992928/

相关文章:

java - LibGDX - Scene2d 无法单击小部件

java - 获取 SoapBody 元素值

validation - 如果两者都设置为必需,如何根据另一个下拉列表设置下拉列表的值

java - JSF 图像下载,Base64 编码保存到数据库

javascript - 混合ajax和完整请求

java - Vaadin 7 示例在部署到 tomcat 7 时显示 "Cookies Disabled"消息

java - 当 spring-boot 应用程序需要来自用户的 stdin 时,Maven 构建暂停

java.lang.IllegalArgumentException : Object would be serialized to `null` : Android 异常

c# - 在 Web 服务 soap 响应中发送二进制文件

web-services - 有没有办法限制对 ASMX Web 服务(即 asmx 页面及其 WSDL)的访问?