简体   繁体   English

JS-使用“&”提交参数的值

[英]JS - Submit parameter's value with “&”

I´m working with a .js referring to a form. 我正在使用.js引用表单。

In a function it sets the form's action and then submit it. 在一个函数中,它设置表单的动作,然后提交。

document.forms[0].action = "FileController.do?action=genFile&fileType="+ft+"&answType="+at;
document.forms[0].submit();

The problem is that answType 's value sometimes has an " & " on it, like " M&M ", so when I try to get that value like this: 问题是answType的值有时在其上带有“ ”,例如“ M&M ”,因此当我尝试获取该值时,如下所示:

String answer = request.getParameter("answType");

I only get the first " M " and lost the rest of the value. 我只得到第一个“ M ”,而失去了其余的值。

I know that's because parameters are separated by " & ". 我知道这是因为参数由“ ”分隔。

But is there a workaround for this? 但这有解决方法吗?

I can't change the original data. 我无法更改原始数据。

Thank's 谢谢

encodeURIComponent(string)会将URL中具有特殊含义的字符(例如& )转换为它们的转义序列。

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

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