Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
在Struts2中获取准确的URL_Url_Struts2 - Fatal编程技术网

在Struts2中获取准确的URL

在Struts2中获取准确的URL,url,struts2,Url,Struts2,我想获取Struts2 web应用程序访问的URL。例如,如果用户访问http://www.webpage.com 或https://www.webpage.com,我需要协议;http或https。我尝试使用ServletRequestAware并使用request.isSecure或request.getScheme实现该操作。然而,即使我访问了“http”,我也会得到false和“http”https://..“链接 有没有办法获取协议?您可以从标题中提取协议: System.out.pr

我想获取Struts2 web应用程序访问的URL。例如,如果用户访问http://www.webpage.com 或https://www.webpage.com,我需要协议;http或https。我尝试使用ServletRequestAware并使用request.isSecure或request.getScheme实现该操作。然而,即使我访问了“http”,我也会得到false和“http”https://..“链接


有没有办法获取协议?

您可以从标题中提取协议:

System.out.println(request.getHeader("referer"));
输出:


我想你忘了再试一件事了。 使用ServletRequestAware和use实现操作

request.getProtocol();
否则,您可以在action类中使用以下代码:

HttpServletRequest request=ServletActionContext.getRequest();
    String protocol=request.getProtocol();
    System.out.println("Protocol Used::"+protocol);

我的输出为null。然后确实出了问题。请发布获取请求对象的方式。action类实现ServletRequestAware。我有一个被设置的私有HttpServletRequest变量。该操作是否也扩展了ActionSupport?是的。它扩展了ActionSupport。我正在使用协议::HTTP/1.1作为输出,所以您实际上得到了您想要的正确的协议。嗯。。事实上,我需要检查它是否是使用http或httpsSo访问的。您是想检查您的应用程序是否是使用htttp或https访问的吗?我说的对吗?然后都德。。。如果您遇到问题,只能使用http访问您的应用程序,因为。。。除非您已将SSL添加到应用程序中,否则永远无法使用https访问它。一旦您添加了SSL,即使有人键入http+网站。。SSL使其成为https:尝试使用http访问facebook,它涉及https:。。所以我想我现在已经正确地回答了你的答案: