Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jsp中获取主机地址?_Jsp_Struts2 - Fatal编程技术网

如何在jsp中获取主机地址?

如何在jsp中获取主机地址?,jsp,struts2,Jsp,Struts2,我有以下标签,需要它重定向到以下地址localhost/signup 如果我的地址很深,比如localhost/users/profile/view,点击这个链接就会转到 localhost/users/profile/signup 如何强制它从任何深度的地址重定向到localhost/signup,而不在地址开头添加localhost?可能吗 <a href="<s:url action="../signup"/>">Sign Up</a> 试一试

我有以下标签,需要它重定向到以下地址
localhost/signup

如果我的地址很深,比如
localhost/users/profile/view
,点击这个链接就会转到
localhost/users/profile/signup

如何强制它从任何深度的地址重定向到
localhost/signup
,而不在地址开头添加
localhost
?可能吗

   <a href="<s:url action="../signup"/>">Sign Up</a> 

试一试:

<a href="<s:url action="~/signup"/>">Sign Up</a>

以上内容似乎在ASP.NET中工作,我相信它也应该在JSP中工作


简单的一件事是,当您放置
。/SomeMethod
时,服务器会在单击链接的同一目录中查找
SomeMethod

试试:

<a href="<s:url action="~/signup"/>">Sign Up</a>

以上内容似乎在ASP.NET中工作,我相信它也应该在JSP中工作


简单的一件事,当您放置
./SomeMethod
时,服务器会在单击链接的同一目录中查找
SomeMethod

我的首选方法是永远不要硬编码斜杠前缀(
/signup
)或相对(
./signup
),而是使用
对上下文根路径进行软编码:


我的首选方法是从不硬编码斜杠前缀(
/signup
)或相对(
。/signup
),而是使用
对上下文根路径进行软编码:


谢谢,我知道../但不知道如何进入根目录,~在注册前加上自己的前缀新地址是localhost/users/profile/~/signupPlease请不要混淆Struts2和JSP。我不做Struts2,但这在JSP中肯定不起作用。谢谢,我知道../但不知道如何进入根目录,~在注册前加上前缀,新地址是localhost/users/profile/~/signupPlease请不要将Struts2与JSP混淆。我不使用Struts2,但这在JSP中肯定不起作用。
<a href="${root}/signup"/>Sign Up</a>
Host/Context Path: http://localhost/blah                 Link: http://localhost/blah/signup
Host/Context Path: http://localhost/mycoolco/secret/blah Link: http://localhost/mycoolco/secret/blah/signup