how to pass values from javascript to servlet without adding inthe URL

Posted on 2010-01-07
Last Modified: 2013-11-21
I am getting somevalues in the javascript function, now i want to send these values to servlet without putting these in the URL. since my values contain special characters, if i add it in the URL and send it to Servelt , getting errors. Can anybody help me on how to pass values from javascript to servlet without adding in theURL.
Question by:kbb1
    LVL 27

    Expert Comment

    You should use post as your method.  
    <form  method="post"    ...
    LVL 27

    Expert Comment


    Author Comment

    i am getting some values based on <td> id . there is no form here, so i cannt pass it by post method.
    my code is something like

    var checkedRow = document.getElementById(j);
                        var checkedCells = checkedRow.getElementsByTagName("td");
                             var title =checkedCells[1].innerText;
                  var size=checkedCells[2].innerText;
              var maxlimit=checkedCells[3].innerText;

    and i need to dispaly these values thorugh a servlet
    LVL 40

    Expert Comment

    insert these values to a hidden input
    <input type='hidden' name='hidden1' id='hidden1'>

    and fetch these values in the servlet by
    LVL 20

    Expert Comment

    by:Sathish David Kumar N
    use hidden filed !!

    set the value to the flied in java script

    like this

    now u can get the form flied values in ur servlet as ur other flied getting  !!
    LVL 27

    Accepted Solution

    You didn't tell us what you want to occur after you submit values to the server.
    Do you want to refresh the page ?
    Do you want to go to another page ?
    Do you want to stay on same page with no action ?  

    > there is no form here  
    You can hide the form by using CSS. You can also programmatically  submit it. Please look at example code below here.  

    If you don't want any action, then you could use AJAX.  
                       form{display:none; }
                        function SubmitForm(){
                                    document.myHiddenForm.param1.value = "1234";
          <button type="button" name="mybutton" onclick="SubmitForm();" >submitHiddenForm</button>
          <form name="myHiddenForm" method="post" action="parameters.jsp" >
          <input type="text" name="param1" />

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
    Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now