Assign Javascript Value to JSP

I have a dynamic link that links to a Javascript function:
test
The javascript function:
function frames(testing)
<%=testHere%> = testing
<%
HttpSession testSession = request.getSession(true);
testSession.putValue("tested", testHere);
%>
I want to assign the javascript value, testing, into JSP value,testHere, which will be place in the session, which is :~
.......putValue("tested", testHere).
Does anyone know how to solve it? =)
Thanks in advance...

You can't. As is stated here about 3 times a day, Java, the JSP code, and servlets run on the Server, while javascript runs on the client (in the browser). By the time javascript begins to run, the JSP is compiled, run, the response generated and sent to the browser as HTML.
The only means to do this is to send the variable back to the browser by requesting the same or another page and including the javascript value as a parameter to that page.

Similar Messages

  • Passing JavaScript value to Jsp

    Hi,
    Any idea how to pass a value from javascript to jsp page when the page gets load on browser.
    I use below code but an event is require to pass the value. Is there any code that pass automatically the value from javascript to jsp.
    <html>
    <head>
    <title>Passing Javascript value to Jsp</title>
    <script type="text/javascript" language="javascript">
    var scriptVar = "Noy"
    var WinNetwork = new ActiveXObject("WScript.Network")
    document.write (WinNetwork.username)
    document.index.hiddenTextBox.value = WinNetwork.username
    </script>
    </head>
    <%
    String jspVar = null;
    if(request.getParameter("submit") != null){
         jspVar = request.getParameter("hiddenTextBox");
         out.println("Jsp Var : " + jspVar);
    %>
    <body>
    <form name="index" onSubmit="index.jsp" method="post">
    <input type="hidden" name="hiddenTextBox"><br>
    <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </html>
    Thanks,
    ~ukbasak

    JSP/Java runs at the server side, produces a HTML page, sends it to the client side and then stops running.
    HTML, containing under each CSS and JS, arrives at the client side and runs at the client side only.
    To invoke JSP/Java using HTML you need to fire a request to the server side. That can be either a plain vanilla <a> link, a <form> to be submitted or an asynchronous Ajaxical request.
    That said, the use of ActiveX in web applications is discouraged. It's a Microsoft IE proprietaty. With other words, it isn't and won't be supported by all alternative browsers which the other half of the world is using.

  • Passing JavaScript values to JSP variables

    Can any body correct the follwing code
    <Script language="JavaScript">
    function test( x )
    <%
    int num = x;
    num = num * 2;
    %>
    v.value = "<%out.print(num);%>";
    <input type="button" name="b" value="test" onClick="test(5)">
    <input type="text" name="v" value="0">
    In short, I am trying to pass JavaScript value to JSP variable. I hope that it is possible to do that. If it is possible then how can I do it. I want to assing the variable x passed to the JavaScript function called test to the JSP variable called num.
    Regards,
    Ageel

    Thank you for your reply,,,
    I think then the only way to do it is to post the
    value on the server and then use request.getParameter
    method in jsp code
    but the question now how can I post values to the
    server using JavaScript without reloading the pageyes... you can to it by create a new popup window which will submit the value to server after page was loaded... then, server return a value to the same window in html/jsp page which then using javascript to set it back to the opener and close up the window... however, this is not a good choice unless you have no other alternative...
    >
    There is other possible solution
    if I can get the text field value from the same page
    without reloading it that would work fine and will
    solve my problem, is it possible?yes... you can get the value from the textfield...
    for example :
    function showValueInTextField()
        alert(document.forms[0].elements["mytextfieldname"].value);
    >
    My final question> can jsp change things on the same
    page without reloading it. I mean can it work like
    JavaScript so that I can use it's internal functions
    instead of using java script :S
    not really know what you trying to say here...

  • How can I assign javascript variables to jsp or java variables.?

    How can I assign javascript variables to jsp or java variables.?

    See I have generated some variables in the javascript which is on the jsp page. I want to assgin these variables to the jsp vaiables. Or how can I access javascript variables from jsp on the same jsp page.

  • Assigning javascript array with jsp array

    hi,
    I have a jsp page where I have a array in jsp. I want to assign the values to an javascipt array. how can I do that?
    the reason why I want to do this is for a perticular problem I am facing in javascript. that is....
    I have a text box in my jsp page, I want the value entered in that box to be checked (whether it exists ) against a hidden string which has some value. I want that hidden string not to be shown to the user even on seeing the html source. that is why I want these values to be stored and checked against a array object of javascript.
    any suggestion is appreciated
    Thanks
    Ashutosh

    Hai asutoshdash
    if you dont mind of viewing code u can use this else dont use, its not matters weatehr user will see you code or not if the user is professiona then its a big issue normal users not think of is for this dont send valuable infos like password etc to client u may send usernames
    ok to create a java array to javascript array do this (i took example of db to array ) write this inside <script> <%codes here%> </script>
    var aUsername =new array();
    <%
    int i=0;
    while (rs.next())
    %>
    aUsername[<%= ++i%>] = "<%= rs.getString("User_Name")%>";
    <%
    %>thats it use this array where ever you want in your client side(javascript ) usage
    hope this will help you
    archi

  • Passing javascript values to jsp without refreshing the page

    Hi,
    How do u pass a value of a javascript variable to the jsp without refreshing the page ?
    For example, a file called test.jsp in which a javascript variable x contains value 254. I need to pass the value of x to a method declared in test.jsp(same page).

    Hi Mona,
    when i say refresh i do mean a blink of the browser.
    This is a small example i wrote to show you how you can pass javascript varables to JSP variables. If you don't want the refresh to be seen by the user just include this code in a hidden frame on a page and instead of refreshing the entire page, refresh the hidden frame.
    i have to say, i didn't test the code so i don't guarantee it's flawless.
    if you need an more detailed example just tell me, i'll create one, but it won't be for today :)
    <html>
    <head>
         <title>Log in to the system</title>
    </head>
    <body>
    <script>
    //we retrieve the parameter 'user' from the URL
    <%
      String username = request.getParameter("user");
    %>
    var user = "<%= username%>";
    //check if there is a username in the URL
    if(user=="null")
      //there is no username so we log the person in as a guest
      user="guest";
      //we refresh the page and set the user parameter to 'guest'
      //the parameter now contains the javascript variable 'user'.
      //The parameter can be read by the JSP (see the top op this script).
      //This way we gave the javascript variabele to the JSP variable
      location="login.jsp?user="+user;
    else if(user=="guest")
    {  alert("Welcome "+user+", I hope you like this site"); }
    else
    {  alert("Welcome "+user+", I'm glad to see you again"); }
    </script>
    </body>
    </html>

  • Assigning Javascript value to ABAP variables

    Hi Experts,
    I have written the HTML code mixed with Javascripts to create a table in the 'View' of a BSP Component.
    I was able to set the value of assign the value of ABAP parameters into HTML fields.
    This table has some input fields. I need to fetch the value of input parameters which has been entered by screen on an event which is present in Overview Page.
    I can calulate the value mentioned in input field but i am not able to assign the same value to ABAP parameter for further processing.
    I have already referred the following link but it did not work.
    Assign Javascript variable to Abap variable
    Please help me how i should i acheive it.
    Thanks In Advance,
    Rajeev Singh

    Hi,
    I am not understanding your problem and what you want due to description, but it seems to be very similar to a post which I answered very recently [here|How to return values from a BSP page to Javascript;.

  • Passing javascript value to jsp param

    Hi all,
    I want to be able to pass the return value of function getUrl() to jsp param...Is this a correct way? it's not working.... What should I assign to the value of param?
    <HTML>
    <HEAD>
    </HEAD>
    <script language="javascript">
    function getUrl()
         var url=window.location;
         return url;
    </script>
    <BODY>
    <jsp:include page='GetFileServlet' flush="true" >
    <jsp:param name="url" value= "return getUrl()"/>
    </jsp:include>
    </BODY>
    </HTML>
    thank you for your time and assistance

    Hi all,
    I want to be able to pass the return value of
    function getUrl() to jsp param...Is this a correct
    way? it's not working.... What should I assign to
    the value of param?
    <HTML>
    <HEAD>
    </HEAD>
    <script language="javascript">
    function getUrl()
         var url=window.location;
         return url;
    </script>
    <BODY>
    <jsp:include page='GetFileServlet' flush="true" >
    <jsp:param name="url" value= "return getUrl()"/>
    </jsp:include>
    </BODY>
    </HTML>
    thank you for your time and assistanceThis can't be done, since the jsp call will be exercised on the server, before the page gets sent to the user, while the javascript gets performed on the client (well after the jsp is done its job).
    An all server-side solution would be what you needed:
    <HTML>
        <HEAD>
        </HEAD>
        <BODY>
            <jsp:include page='GetFileServlet' flush="true" >
                <jsp:param name="url" value= "<%=request.getRequestURL()%>"/>
            </jsp:include>
        </BODY>
    </HTML>

  • How to pass JavaScript value to JSP variable

    I know this is not possible. But I need to do this :
    <script language = "Javascript">
    function findElement() {
    for(i=0; i<document.forms[0].elements.length; i++){
    if(document.forms[0].elements.type == 'text') {
    var elName = document.forms[0].elements.name;
    var elValue = document.forms[0].elements.value;
    // Display element name and value
    //alert(elName +' = '+ elValue)
    <%
    String elName = elName;
    System.setProperty(%>elName<%, %>elValue<%);
    %>
    </script>
    in JSP. I need to get the name and value of the textbox in the form to just change one property on the JSP System. Any help pls

    Thanks man, I think that would work.
    I found something else already though and it works on the same page
    <%
         Enumeration parameters = request.getParameterNames();
         String parameterValue = " ";
         String parameterName = " ";
                   while (parameters.hasMoreElements()) {
                        parameterName = (String) parameters.nextElement();
                        parameterValue = request.getParameter(parameterName);
                   out.println("NAME =========" + parameterName);
                   out.println("VALUE =========" + parameterValue);
                   //System.setProperty(parameterName, parameterValue);
         %>
    Thanks again for the help

  • Passing Javascript values to JSP

    Hi,
    I have a select box and i get the selected value using the javascript. The variable that stores the value should be passed to the JSP. I need to know , how i an do the same.
    When a user clicks on a option I call a javascript function:
    function myFun()
    var text = document.myform.selectboxname.options[index].text;
    return text;
    I need to get the value returned.
    The select option is as follows.
    <select name="sel" multiple onChange=myFun()>
    How can i get the value "text".
    Kindly help.

    if yes.....my functions returns a value...how can i
    access the same.You can't, in the way you want it. You need the function to put the value where it's supposed to go.
    I'm sorry, but this question is clearly out of scope for this board. Look for a Javascript support forum. Just the fact that the HTML originated from a JSP doesn't make it a Java question.

  • jsp:include ..... javascript value

    It there any way to insert a javascript value into
    <jsp:include page="/master/getcpr.do" flush="true" /> as a parameter.
    I want something like
    <jsp:include page="/master/getcpr.do?value=javascriptValue" flush="true" />
    BR
    Soren

    Try:
    <jsp:include page="..." >
    <jsp:param name="param1" value="value1"/>
    </jsp:include>

  • Assigning a javascript value to a JSP variable

    How do i assign a javascript value to a JSP variable?
    eg
    <%
    String JSPvar;
    %>
    <script language="JavaScript1.2">
    <!--
    var javascriptVar="hey"
    -->
    </script>
    <%
    JSPvar = javascriptVar ???
    %>

    You do know that the JSP runs on the server and generates HTML, including Javascript, that is executed on the client, don't you?

  • I want to assign the value of a Javascript variable to JSP Variable

    I want to assign the value of a Javascript variable to JSP Variable .. for example :
    <%
    Bla Bla Bla
    %>
    <script>
    var JavaScriptVariable="hello"
    </script>
    <%
    String JSPVariable=// The Value of JavaScriptVariable ;
    %>
    How can i do that ??
    Thanks

    >I want to assign the value of a Javascript variable to JSP Variable
    cannot be done.Friend try to understand concepts properly Javascript is always excuted by the browser @clientside where as JSPCode is executed Websever(ServletContainer) @serverside.Through you are combining JSP Code blocks(Tags,Expressions,scriptlets...) & javascript under a single page webserver can only identify what is their under JSP Code blocks.
    Hope this could be an appropriate answer for your question.
    However,you can as well submit a request by encoding your URL with request parameters and the submit to the page and then collect it using request.getParameter(name).
    But under a single context state it is not possible
    REGARDS,
    RaHuL

  • How can i assign a Javascript variable to JSP variable

    Hi guys
    how i can assign a javascript variable to jsp expression.,
    e.g.,
    <input type = "button" value = "Add more" onclick = "return submitform1('<%=s%>')">
    function submitform1(String s)
          var s1 = s
    document.form1.action = "../intimation.do";    /* Here i want to pass the value s1 to jsp or servlets without using hidden fields and Query string*/
           document.form1.submit();
          return false;
    /*  i want to pass the values thru session whether it is possible */
    pls give sample code
    Reply
    Marimuthu

    You don't have the session.
    All you have is HTTP.
    The only way to communicate from the client to the server is via an HTTP request. The only way to send a value like that is with a parameter.
    Using a form with method="submit" as mentioned will pass the parameters without displaying them in the url bar (is that what you wanted?)

  • Assigning return value of a javascript function to a variable

    hi.
    I have a javascript function which returns string.
    I wanna assing return value of that function to variable.
    for example:
    <script>
    funtion writeMe()
    var ex;
    ex="try"
    return ex;
    </script>
    Then in body of JSP page. I wanna do something like:
    <% String st;%>
    Now I wanna assign the value that returned from writeMe function ("try") to st string.like:
    <%st= writeMe();%>. but of course it doesn't work. how can I do that?

    thnx. but actually what I want to do is sending some values produced by javascript to a barchart object. is it impossible too?
    I mean my script function returns something like "100, 200, 300". I wanna pass that values to barchart. when I want to add aplet tag to jsp code instead of writing:
    <param name="s1_value" value="100,200,300">
    I want to write somethin like:
    <param name="s1_value" value="myscriptfunction()">
    is it possible in JSP? I saw an example like this in asp. it was like:
    <param name="sampleLabels" value="<%call func1()>">. but in JSP it seems like call tag doesn't work. Is it possible in JSP?

Maybe you are looking for

  • 7th gen iPod Nano not recognized with Windows 8

    I am running Win8 and am having trouble getting my 7th gen Nano to be recognized either as a device on my PC or in iTunes. Is the Nano compatible with Win8? I have worked thru many of the troubleshooting guides and Apple support pages. Have the most

  • Small, cheap NAS box that supports nfs/rsync/ssh ?

    Hi all, for my personal backup needs, I'm looking for a standalone NAS box ("networked hard disk/raid solution").  I need to have support for at least one of rsync/nfs/ssh.  (smb/ftp is not enough for me) It shouldn't be too big (eg not the size of a

  • In photoshop Elements 10 how do you calibrate colr/density output to Epson Artisan printers?

    The colors printed by my Epson artisan printer, particularly the blues and greens, are not true to the photoshop colors, and the Epson prints are darker, denser, and have substantially less [punch than the screen images.I have tried about every setti

  • A webservice dont want to deploy and run (because of weblogic.jar)

    Good Afternoon! I have a JDeveloper 11g Release 1 (11.1.1.3.0) And I have a simple webservice. (A simple Class i converted to webservice.) Trying to test it (RMC on file -> Test Web Service) i got a fail like this: [Running application SimpleWSApll o

  • Updating TOC in INDESIGN CS6

    How do I update only the page numbers in my own formatted TOC without having to redo the formatting after making many changes in the document?