I am trying to pass special characters as querystring in url as part of GET request. I am constructiong that string in javascript function.

我试图在URL中传递特殊字符作为查询字符串作为GET请求的一部分。我在javascript函数中构造该字符串。

var queryString = "list=ABC-48+12&level=first";

Then I append the string to url as part of request which goes to struts action class. In the action class I get the "list" value as "ABC-48 12", the "+" character is not passed. How to pass special characters in the string as part of url and get back in the java class?

然后我将字符串附加到url作为请求的一部分,该请求转到struts动作类。在动作类中,我将“list”值设为“ABC-48 12”,不传递“+”字符。如何在字符串中传递特殊字符作为url的一部分并返回java类?

Please let me know.

请告诉我。

Thanks.

2 个解决方案

#1


-2

You need to use a regular expression with the global option set as the first parameter instead of a string: (in regular expressions "+" is a special character, so we have to escape it with a backslash.)

你需要使用一个正则表达式,将全局选项设置为第一个参数而不是字符串:(在正则表达式中,“+”是一个特殊字符,所以我们必须用反斜杠转义它。)

safeQueryString = safeQueryString.replace(/+/g, '%2B');

safeQueryString = safeQueryString.replace(/ + / g,'%2B');

更多相关文章

  1. JSON.parse(xhr.responseText)意外的字符串错误
  2. JS计算任意字符串宽度
  3. 如何在JavaScript中按大写和小写分割字符串?
  4. 使用jackson json将属性添加到json字符串
  5. ajax请求返回一个空字符串作为响应
  6. 在Javascript中将带有空格的字符串数组转换为小写,然后在Webkit中
  7. 如何将带有双引号反斜杠的JSON字符串转换为Javascript对象
  8. Javascript正则表达式应该允许空和非空字符串,但它不会
  9. 获取拆分字符串数组的最后一个元素

随机推荐

  1. Android自定义视图二:用Canvas和Paint绘制
  2. Android Studio打包apk,aar,jar包 总结
  3. android 发送语音功能和ios交互格式aac
  4. Android(安卓)Material Design 之 Bottom
  5. 巨好的入门写精通
  6. Android 月活跃人数超过10亿用户了,我却审
  7. Android菜鸟的成长笔记(15)—— Android中
  8. Android使用Linux mount获取SdCard存储目
  9. Android(安卓)10 获取剪切板内容
  10. Android(安卓)cannot access localhost?