简体   繁体   中英

Encoded characters in string preventing form from being submitted

I have the following 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. 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?
  • How can I make submit() launch the decoded link?

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. I declared a variable rootPath = "${pageContext.request.contextPath}" and afterwards

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

Now everything works as desired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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