首页 > 解决方案 > 如何在同一页面中将我已为 JSP 标记分配动态值的 JavaScript 变量值分配论坛提交时返回 false

问题描述

我需要为同一页面中的 JSP 分配一个 JavaScript 变量以从 JSP servlet 获取结果。请看一下代码。

function resendMail(username){
       <% 
       String failusername = username;
       %> 
        var redirectUrl = "https://localhost:9444/authenticationendpoint/login.do?resend_username=<%=Encode.forHtml(failusername)%>&<%=AuthenticationEndpointUtil.cleanErrorMessages(Encode.forJava(request.getQueryString()))%>";
        window.location.href = redirectUrl;
    }

我试过关注....我把它保存在 JSP 论坛中:

<input type="hidden" id="foo" name="foo" />

执行了这个脚本:

document.getElementById("foo").value = "some value";

我已经提交了表格(当返回 false 时):

String foo = request.getParameter("foo"); // "got null"

我也在下面尝试过

<html>
<script language="javascript" type="text/javascript">
    function call(){
        var name = "xyz";
        window.location.replace("a.jsp?name="+name);
    }
</script>
<input type="button" value="Get" onclick='call()'>
<%
    String name=request.getParameter("name");
    if(name!=null){
        out.println(name);
    }
%>
如果我使用它,上述一个工作但不适合我的情况,查询字符串正在改变,因为我遇到了问题。

只是我想在论坛提交返回 false 时将 JavaScript 变量传递给同一 Jsp 页面中的 Jsp。

任何人请帮助我提前获得解决方案谢谢

标签: javascriptlinuxxmlvue.jsjsp

解决方案


推荐阅读