传递Euro Sign作为网址参数的问题 [英] Problems with passing Euro Sign as URL parameter

查看:240
本文介绍了传递Euro Sign作为网址参数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过欧元(€)符号作为url参数在我的春天jsp。什么是正确的方式这样做?我试过以下没有效果。问题是字符被正确编码,但没有从我的目标jsp解码。



我使用



<%@ page contentType =text / html; charset = UTF-8%>



是调用jsp:




< script>
...
// params包含欧元符号
document.location ='dest.jsp?p ='+ escape(params);



在dest.jsp



< input type =hiddenid = value =$ {param.p}>
和在同一页面的脚本
console.log当我使用escape(params)时,我得到的url作为%par())。

$($ par $'par')val())



    u20AC。但在dest.jsp
  • 中没有(空)值,当我使用encodeURI(params)或encodeURIComponent时,我得到url为€。但是dest.jsp中的值为⬠- 我不能用来呈现欧元符号


解决方案

您需要对€符号进行编码,该符号应该赋予%E2%82%AC UTF-8 。您需要小心使用两端的编码。



客户端上的 URLEncoder.encode(url,UTF-8) p>

如果你使用Spring, org.springframework.web.util.UriUtils 也有很好的实用程序可以使用。 / p>

如果解码问题在服务器上,您需要首先确保您的Web容器使用正确的编码解码URI。



Tomcat默认会以 ISO-8859-1 解码URI,因此您需要更新连接器配置

 < Connector port =8080... 
URIEncoding =UTF-8/&


I am trying to pass the Euro ( € ) sign as url parameter in my spring jsp. What is the right way to do so ? I tried the following with no avail. Problem is the character is getting encoded properly but not getting decoded from my destination jsp.

I am using

<%@page contentType="text/html;charset=UTF-8" %>

Here is the calling jsp:

<script> ... // params contains the euro sign document.location='dest.jsp?p='+escape(params);

In the dest.jsp

<input type="hidden" id="par" value="${param.p}"> and in a script in the same page console.log($('#par').val())

  • when I use escape(params) I get the url as %u20AC . But no (empty) values in the dest.jsp
  • when I use encodeURI(params) or encodeURIComponent I get url as € . But the value in dest.jsp as ⬠- something which I can't use to render as euro sign

解决方案

You need indeed to encode the € sign which should give %E2%82%AC using UTF-8. You need to be careful with the encoding you use on both ends.

Something like URLEncoder.encode(url, "UTF-8") on the client would do.

If you are using Spring, org.springframework.web.util.UriUtils has also nice utilities you can use.

If the decoding issue is on the server, you need first to make sure that your web container decodes the URI with the proper encoding.

Tomcat decodes URI with ISO-8859-1 by default so you need to update your connector configuration

<Connector port="8080" ... 
           URIEncoding="UTF-8"/>

这篇关于传递Euro Sign作为网址参数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆