避免URL编码 [英] Avoid URL Encoding
问题描述
我在struts 2应用程序中遇到了与URL编码有关的问题.我做了一些研究,但找不到正确的方法.
I'm having an issue related to url encoding in my struts 2 application. I did some research but could not find the correct way to do this.
我的应用程序动态地准备url并通过查询数据库来获取变量.我期望的有效URL是
http://www .test.com/language = english& numbers = X,Y,Z
My application prepares the url dynamically and gets the variable by querying the database. The valid URL that I'm expecting is
http://www.test.com/language=english&numbers=X,Y,Z
但是,由于URL编码而在UI上时,我得到的URL如下所示
http://www.test.com/language=english&numbers=X %2CY%2CZ
However, when on UI because of URL encoding i get the URL as below
http://www.test.com/language=english&numbers=X%2CY%2CZ
numbers是一个变量,数据库返回的值为X,Y,Z.
numbers is a single variable and database returns the value as X,Y,Z.
我正在按以下方式在jsp中准备URL
I'm preparing the URL in jsp as below
<s:url id="testUrl" escapeAmp="false" value="http://www.test.com">
<s:param name="language" value="%{'english'}" />
<s:param name="numbers" value="%{Num}" />
</s:url>
我曾尝试在 s:url 标记中尝试 encode ="false" ,但无济于事.
I did try encode="false" in the s:url tag but to no avail.
testUrl超链接如下
The testUrl is is hyperlinked as below
<a href="<s:property value="#testUrl" />" target="_blank">
<s:property value="#Num" />
</a>
我知道逗号(,)是保留字符,应进行编码.但是,在我的URL中,我需要该逗号,以便在单击时成功执行url.
我正在使用字符集 iso-8859-1 .
I understand that comma(,) is a reserved character and should be encoded. However, in my URL i need that comma so as to execute the url successfully when clicked.
I'm using char set iso-8859-1.
推荐答案
对于每个人来说,这可能不是最好的方法,但我能够使用javascript来使其正常工作.我已经对该功能进行了彻底的测试,并且目前已达到我的目的.
我没有控制修改该URL的权限,因为它是第三方URL.
This may not be best approach for everyone but i was able to get this working using javascript. I tested the functionality thoroughly and it is currently serving my purpose.
I did not have control to modify the URL as it was a third party URL.
因此,当用户单击我网站上的超链接时,将调用Java脚本.该URL会被解码并在新窗口中打开.
So when a User clicks on a hyperlink on my website, a java script is called. The URL gets decoded and opens up in a new window.
<a href="#" onclick="decodeURL('<s:property value="#testUrl"/>')">
<s:property value="#Num" />
</a>
JavaScript
Javascript
function decodeURL(url) {
var url_dec = decodeURIComponent(url);
window.open(url_dec);
}
这篇关于避免URL编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!