简体   繁体   中英

how to access javascript variable in scriplet jsp

I have a javascript variable say,

var a ='2013-01-03' 

I want to access this variable inside my scriptlet . ie] I have a map that contains my data.
I want to fetch the value of the map corresponding to the key='2013-01-03' that is in javascript variable 'a' .

How can i use like following in my scriptlet.?

map.get(a);

I know the scriptlets will execute first even then without reloading I want to access the variable a inside my scriptlet . Can any one help me solve this problem.?

You need to submit client data (javascript) to the server (servlets, jsp). You can do it without reloading a page using ajax.

You have not mentioned the action for which to perform operation .Assuming If you are making call on focuslost then

$('#yourdom').blur(function() {
        serverCall;

    });




function serverCall{
        $('#yourdom').val('2013-01-03')

            $('#form').submit();


    }

In servlet

String value=request.getParameter("yourdom");
request.setAttribute("test",value);
RequestDispatcher rd = request.getRequestDispatcher("your.jsp");  
  rd.forward(request,response);

In jsp

<% request.getAttribute("test")  %>

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