Getting Paramter value passed in Java Script function to JSP code

Posted on 2006-06-05
Last Modified: 2010-04-01
Hello and how is everyone. Can I do get a value from a JavaScript parameter that is passed from my web form and get that into my JSP code variable. For ex:


var JSVariable =  var nodeId2 = document.getElementById(nodeId).value;

 Now in my JSP code I want to get that value of JSVariable.


Question by:Corey_819
    LVL 5

    Expert Comment

    Javascript is client-side, scripplet code is server-side, you can't really intermingle them like you are trying to do.

    What you need to do, is take the javascript variable, and pass that along to another page via a form-post or on a query string, then in the next jsp you hit you can process the value.

    <-- original page -->

        var JSVariable =  var nodeId2 = document.getElementById(nodeId).value;
        location.href = "/myNextJsp.jsp?val="+JSVariable;


    <-- myNextJsp.jsp --->

        String myVal = (String)request.getParameter("val");
         .... //do whatever

    LVL 1

    Author Comment

    Okay it is not null no more, but it is nothing just blank

     String SelectedNodeId =  (String)request.getParameter("val");

    however the link is as:

    http://localhost:8084/TandDRegistratonForm/index.jsp?val=#1 LTW-CLINICAL DECISION MAKING

    LVL 5

    Accepted Solution

    OK, thats because the parameter, val=something cannot have spaces in it, and I suppose that the pound sign maybe an issue too.

    In the javascript that creates the link, do something like this:

      var JSVariable =  escape(document.getElementById(nodeId).value);
       location.href = "/myNextJsp.jsp?val="+JSVariable;


    you have to encode the spaces in your parameter, the resulting val= should have some ampersands and maybe "+" signs.
    That should work, I'm not sure if you will have to decode it in the scriplet, if you do user URLDecoder:

    Let me know if that works


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    Title # Comments Views Activity
    jersey maven project error 7 126
    constructor overloading 2 70
    grep code 4 134
    equalIsNot  challenge 43 90
    This post first appeared at Oracleinaction  ( Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
    This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    760 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

    15 Experts available now in Live!

    Get 1:1 Help Now