如何在jsp中访问javascript变量 [英] how to access the javascript variable in jsp

查看:653
本文介绍了如何在jsp中访问javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在jsp页面scriptlet中获取JavaScript变量我正在尝试获取空值,请帮助我。

I want to get JavaScript variable in jsp page scriptlet i am trying alot its getting null value please help me out.

mycode:

<script>
    function setacademicyear(ele){
        alert("ele"+ele);  
        request.setAttribute("ayear", ele);
    }

    <%
        if (request.getAttribute("ayear") != null) {
            String ayear1 = (String) request.getAttribute("ayear");
            System.out.println("ayear1ayear1ayear1" + ayear1);
            Academicyearmaster acy = (Academicyearmaster) ses.get(Academicyearmaster.class, Long.valueOf(ayear1));
            request.getSession().setAttribute("academicyear", acy);
        }%>  
</script>


推荐答案

你不能。 JSP正在服务器上进行处理;然后客户端接管并且JavaScript可以处理。除非在新请求中,否则您无法将值从JavaScript传递到JSP。

You cannot. JSP is processing on the server; then the client takes over and JavaScript can process. You cannot pass values from JavaScript to JSP except in a new request.

想象一下您前往莫斯科,当您到达那里时,您会要求您的母亲提醒您一种与她取得联系的方式。已经太晚了,她无法联系,你必须自己记住它。

Imagine you were traveling to Moscow, and you ask your mother to remind you when you get there to find a way to get in touch with her. It's too late, she can't make contact, you have to remember it by yourself.

这篇关于如何在jsp中访问javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆