Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将JavaScript变量转换为Java变量?_Java_Javascript - Fatal编程技术网

如何将JavaScript变量转换为Java变量?

如何将JavaScript变量转换为Java变量?,java,javascript,Java,Javascript,我需要将JavaScript中的变量转换为Java变量。我通过测试框向用户询问他们的电子邮件ID,并弹出一个块UI。如果字段既不为null也不为空,则应将电子邮件id发送到会话变量,以便可以在项目中的任何位置访问它 这是我的密码: function sbtEmail(){ var email = document.getElementById("EmailId").value; if (email == null || email == ""){ alert("E

我需要将JavaScript中的变量转换为Java变量。我通过测试框向用户询问他们的电子邮件ID,并弹出一个块UI。如果字段既不为null也不为空,则应将电子邮件id发送到会话变量,以便可以在项目中的任何位置访问它

这是我的密码:

function sbtEmail(){
    var email = document.getElementById("EmailId").value;
    if (email == null || email == ""){
        alert("Enter your contact Email address to continue...!");
        document.getElementById("EmailId").focus();
    } else {
        <%session.setAttribute("quoteEmail",email);%>
        window.location.href = "demo2.jsp";
    }
}
函数sbtEmail(){
var email=document.getElementById(“EmailId”).value;
如果(email==null | | email==“”){
警报(“输入您的联系电子邮件地址以继续…!”;
document.getElementById(“EmailId”).focus();
}否则{
window.location.href=“demo2.jsp”;
}
}

它不起作用。我做错了什么?

您不能直接从JavaScript在会话中设置变量(仅驻留在服务器上!)。您必须以某种请求的形式将它们传递给服务器,然后服务器可以在会话中进行设置。

您不能直接从JavaScript在会话中设置变量(仅驻留在服务器上!)。您必须以某种请求的形式将它们传递给服务器,然后服务器可以在会话中对其进行设置。

已解决:使用Ajax将解决此问题

  <script type="text/javascript" src="../ajax.js"></script>

     <script type="text/javascript">
    function sbtEmail(){
        var email = document.getElementById("anonymousEmailId").value;
        if (email==null||email==""){
            alert("Enter your contact Email address to continue...!");
            document.getElementById("anonymousEmailId").focus();
        }else{
            enqueue("demo1.jsp?Id="+email,ajaxReplay);
        }
    }
    function ajaxReplay(){
        window.location.href="demo.jsp";
    }
    </script>

解决:使用Ajax将解决问题

  <script type="text/javascript" src="../ajax.js"></script>

     <script type="text/javascript">
    function sbtEmail(){
        var email = document.getElementById("anonymousEmailId").value;
        if (email==null||email==""){
            alert("Enter your contact Email address to continue...!");
            document.getElementById("anonymousEmailId").focus();
        }else{
            enqueue("demo1.jsp?Id="+email,ajaxReplay);
        }
    }
    function ajaxReplay(){
        window.location.href="demo.jsp";
    }
    </script>

使用这个Ajax文件:---->eval(函数(p,a,c,k,e,r){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36));if(!'.replace(/^/,String)){while(c--)r[e(c)]=k[c]| | e(c);k=[function(e){return r[e]};e=function(e){return r[e]};e=function=r[e](c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c)c){return(cUse this Ajax file:----> eval(function(p, a, c, k, e, r) { e = function(c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) r[e(c)] = k[c] || e(c); k = [function(e) { return r[e] } ]; e = function() { return '\\w+' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p } ('d 7;f n(a,b,c){6(!7)7=j s;6(!7.n(a,b,c))g l;6(!7.k)7.o();g h}f s(){3.5=j t();3.8=9;3.k;3.m=h;3.n=f(a,b,c){u(d i=0;i<3.5.p;i++)6(3.5[i][0]==a&&3.5[i][1]==b&&3.5[i][2]==c)g l;6(3.8==9){3.k=l;3.m=h;3.8=0}v{++3.8}3.5[3.8]=j t();3.5[3.8][0]=a;3.5[3.8][1]=b;3.5[3.8][2]=c;6(3.k&&c)w(c);g h};3.o=f(){6(3.8==9||3.5.p==0)g;3.k=h;6(3.m){d r=q();d a;6(r){u(d i=0;i<3.5.p;i++){6(3.5[i][2])w(3.5[i][2])}}3.m=l}3.x(3.5[0][0],3.5[0][1])};3.x=f(a,b){d r=q();6(r){r.E("F",a,h);r.G=f(){6(r.H==4){6(b)b(r.I);7.5.J(0,1);7.8>0?--7.8:7.8=9;6(7.8==9){7.k=l;7.m=h;g}v{7.o()}}};r.K(9)}}}f q(){d A=9;y{A=j z("L.B")}C(e){y{A=j z("M.B")}C(N){A=9}}6(!A&&O D!="P"){A=j D()}g A}', 52, 52, '|||this||queue|if|g_q|position|null||||var||function|return|true||new|isProcessing|false|callPreFunctions|enqueue|process|length|getXMLHTTP||ajaxQueue|Array|for|else|eval|getAjaxQueueResult|try|ActiveXObject||XMLHTTP|catch|XMLHttpRequest|open|GET|onreadystatechange|readyState|responseText|splice|send|Msxml2|Microsoft|oc|typeof|undefined'.split('|'), 0, {}))