gpt4 book ai didi

java - 如何在两个网络应用程序之间导航?

转载 作者:行者123 更新时间:2023-12-01 23:48:44 26 4
gpt4 key购买 nike

如果我有两个网络应用程序 http://www.abc.com/app1http://www.abc.com/app2 我该如何处理两者之间的导航?

我希望能够使用侧边栏中菜单中的链接导航到 app2...

<p:menu>  
<p:menuitem outcome="/index" value="Home" icon="ui-icon-home"/>
<p:submenu label="app1">
<p:menuitem outcome="/page1" value="page1" />
<p:menuitem outcome="/page2" value="page2" />
</p:submenu>
<p:submenu label="app2">
<!-- all the links below should point to pages in app2 -->
<p:menuitem outcome="/pageA" value="pageA" />
<p:menuitem outcome="/pageB" value="pageB" />
</p:submenu>
</p:menu>

显然 outcome="/pageA" 不起作用,因为它试图在 app1 中查找具有该名称的页面,从而导致 404。我尝试过 outcome="/app2/pageA"outcome="../app2/pageA" 但这些都不起作用。还有哪些其他替代方案?

另外,我应该补充一点,我真的不想对网址进行硬编码“http://www.abc.com/app2/pageA”,因为主机名会根据情况而变化关于我在哪里进行部署。

最佳答案

您可以通过执行以下操作来实现它,

托管 Bean:

@ManagedBean  
@ViewScoped
public class YourBean implements Serializable{

String project_path;

public String getProject_path() {
return project_path;
}

public void setProject_path(String project_path) {
this.project_path = project_path;
}

@PostConstruct
public void init() {
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
project_path = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
}

public YourBean() {
}
}

xhtml:

       <p:menu>
<p:menuitem outcome="/index" value="Home" icon="ui-icon-home"/>
<p:submenu label="app1">
<p:menuitem url="#{yourBean.project_path}/app1/page1" value="Page1"/>
<p:menuitem url="#{yourBean.project_path}/app1/page2" value="Page2"/>
</p:submenu>
<p:submenu label="app2">
<p:menuitem url="#{yourBean.project_path}/app1/pageA" value="PageA"/>
<p:menuitem url="#{yourBean.project_path}/app1/pageA" value="PageA"/>
</p:submenu>
</p:menu>

关于java - 如何在两个网络应用程序之间导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16614406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com