简体   繁体   English

用URL附加特殊字符

[英]appending special character with URL

I need help on the issue where we are appending special character like % with URL. 我在将%等特殊字符附加到URL的问题上需要帮助。 Suppose my application URL is " http://www.google.com/ ". 假设我的应用程序网址为“ http://www.google.com/ ”。

we have our custom error page which will come when server will not find URL address. 我们有我们的自定义错误页面,当服务器找不到URL地址时,该页面就会出现。 scenario 1: hitting " http://www.google.com/sdfkdjkfj :---redirecting on custom error page which is correct. 方案1:点击“ http://www.google.com/sdfkdjkfj:---在正确的自定义错误页面上重定向。

Scenario 2: hitting " http://www.google.com/% :--Instead of redirecting on my own custom page it is showing message "this page is not working HTTP ERROR 400". 方案2:点击“ http://www.google.com/%:--而不是在我自己的自定义页面上重定向,而是显示消息“此页面无法正常工作HTTP ERROR 400”。

we are using below code in web.xml to handle the page not found exception. 我们正在使用web.xml中的以下代码来处理未找到页面异常。

 <error-page>
<error-code>404</error-code>
<location>/ErrorPage.jsp</location>

.

Please help on scenario 2 . 请帮助方案2。

If you want to include a % character in a URL, it needs to be percent-encoded; 如果要在URL中包含%字符,则需要对其进行百分比编码。 eg http://www.google.com/%25 . 例如http://www.google.com/%25 (That URL still may not be recognized, but at it is syntactically well-formed.) (该URL可能仍然无法识别,但语法上格式正确。)

Error code 400 means "Bad request", the server cannot understand this request. 错误代码400表示“错误请求”,服务器无法理解该请求。 Generally you should avoid passing special character "%" in your URL like in your example. 通常,应避免像示例中那样在URL中传递特殊字符“%”。 However if you want to pass this character and preserve its meaning, try to encode it: https://www.w3schools.com/tags/ref_urlencode.asp . 但是,如果要传递此字符并保留其含义,请尝试对其进行编码: https : //www.w3schools.com/tags/ref_urlencode.asp When you try http://www.google.com/%25 - you will have 404 error. 当您尝试http://www.google.com/%25时 -您会遇到404错误。

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

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