简体   繁体   English

字符串中的编码字符阻止提交

[英]Encoded characters in string preventing form from being submitted

I have the following Javascript: 我有以下Javascript:

var form = document.createElement("form");
    form.method = "post";
    form.action = "${pageContext.request.contextPath}/login?action=login";
    form.id = "loginForm";

I also have a button that submits() the form above, the problem is that that submit() launches the link by replacing brackets { and } with their ASCII code. 我还有一个按钮,可以使用上面的form submits() ,问题是通过将方括号{}替换为其ASCII代码, submit()启动了链接。 In my browser this appears as: 在我的浏览器中,它显示为:

"$%7BpageContext.request.contextPath%7D/login?action=login"

...instead of: ...代替:

"${pageContext.request.contextPath}/login?action=login"

My questions: 我的问题:

  • How do I force the browser to replace %7B and %7D with { and } , respectively? 如何强制浏览器分别用{}替换%7B%7D
  • How can I make submit() launch the decoded link? 如何使submit()启动解码的链接?

I found out what the problem was: 我发现了问题所在:

"${pageContext.request.contextPath}"

was interpreted literally because it was inside JavaScript file and not inside a variable from jsp. 之所以进行字面解释,是因为它位于JavaScript文件中,而不位于jsp的变量中。 I declared a variable rootPath = "${pageContext.request.contextPath}" and afterwards 我声明了一个变量rootPath =“ $ {pageContext.request.contextPath}”之后

"form.action = rootPath + "/login?action=login";"

Now everything works as desired. 现在一切正常。

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

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