简体   繁体   English

如何从网址中读取参数包含“#”而不是“?”

[英]How to read the parameter from the url contains '#' instead of '?'

How to read access token from this url? 如何从此网址读取访问令牌? When I try to read this by request.getParameter() method it returns null value 当我尝试通过request.getParameter()方法读取此内容时,它返回空值

http://localhost:8080/FirstPick/views/common/home.faces#access_token=xxxxxxxxxx&expires_in=4015

You cant read any parameter from querystring like this.. It must contain '?'. 您不能像这样从querystring中读取任何参数。它必须包含“?”。 Only the string that appears after '?' 仅出现在“?”之后的字符串 is called 'QueryString'. 被称为“ QueryString”。 and from 'QueryString' you can get the value. 并从“ QueryString”中获取值。 And you menstion the url here, is not contain '?' 您在这里提到的网址中不包含“?” so it doesnt have 'QueryString'. 因此它没有“ QueryString”。 and You cant use request.getParameter() method. 并且您不能使用request.getParameter()方法。

Besides this, 除此之外,

Content after the hash (#) is only be used on the client side. 哈希(#)之后的内容仅在客户端使用。 If you require that information on the server, you can use a different separator with query-string using '?', or you can submit it via Ajax after the page has loaded by reading it on the client with JavaScript. 如果在服务器上需要该信息,则可以使用带有'?'的查询字符串使用其他分隔符,或者可以在页面加载后通过使用JavaScript在客户端上读取它来通过Ajax提交该分隔符。

The part of the URI after the hash(#) is never sent to the server, reason is that the hash identifier was originally designed to point at references within the given web page and not to new resources on the server. 哈希(#)之后的URI永不发送到服务器,原因是哈希标识符最初被设计为指向给定网页内的引用,而不是指向服务器上的新资源。

Thanks 谢谢

On client side (ie from JavaScript) you can check window.location.hash to get hash. 在客户端(即从JavaScript),您可以检查window.location.hash以获取哈希。 On server side, general answer is 'it is impossible' since hash is not sent in request to server. 在服务器端,一般的回答是“不可能”,因为没有在请求中向服务器发送哈希。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM