0

I have a Scriptlet inside a function , which gets data from a Session and checks for a value inside the Map

Can i pass the User Selected Option which is a javascript variable to a Map ??

function checker()
{

    var selObj = document.getElementById('selSeaShells');
    var optionselectedvalue = selObj.options[selObj.selectedIndex].value.split(':')[0];
    if(optionselectedvalue==''||optionselectedvalue==null)
    {
        alert('Select a Book');
        return false;
    }

    if (!text_form.quan.value)
    {
        alert('Enter Quantity');
        return false;
    }

    var selectedbook = optionselectedvalue;
    var selectedquantity = text_form.quan.value;

    <%
        Map cart = (Map) session.getAttribute("cart");

        if(cart.containsKey(selectedbook))
        {
            String quant = (String) cart.get(str);

        }

    %>

    return true;
}
johnchen902
  • 9,531
  • 1
  • 27
  • 69

2 Answers2

5

javascript plays on client side and JSP plays on server side.

What you need is you have to make a server request. And send that string a query parameter.

You might misunderstand that jsp and javascript existed on same document. Yes but JSP part compiles on server side itself and JSP output is sent to the client.

So solutions are: either go for html form submit or go for Ajax request.

suspectus
  • 16,548
  • 8
  • 49
  • 57
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

java processing is done at server side and javacript executes on client side. If you do view source on html page you wont find any map.So you can not pass the javascript value to java code (as java code has already been processed by server and its no more).

If you are really want to pass the javascript value to server side you can take help help of ajax or form submission as Baadshah pointed above

M Sach
  • 33,416
  • 76
  • 221
  • 314