Get javascript variable in JSP

Hi all,
can anybody tell me- how to get javascript variable in JSP,
in the same file (JSP).
Is this possible.
I can use JavaScript to get the value,
but then I have no way to get that to the JSP code.
Please give the appripriate answer with code.
Thanks
amitindia

Hi all,
Thanks for your quick response.
So u are right that we can not call javascript variable
in the same JSP. and pass them to the bean class.
So what I did --- I get java script variable in another JSP using
request.getParameter(); and then redirected to previous JSP.
and I have solve my problem.
Actually I had to call bean class and pass varible to the bean
method but I was getting the same problem that I disscussed but now it
has been solved.
Thanks again for participation
amitindia

Similar Messages

  • How to get javascript variable in jsp variable

    Hi all,
    i have a variable str in my javascript function
    var str = somevaluei want this str value in jsp variable in the same page...
    how can this be done..???
    any ideas...
    Thanks

    I dont know if its possible or not.
    Actually it depends on what do you want to do with the variable.
    as far as assisginng value to the hidden variable is concerned it can be done this way.
    <% jsp code
    String hiddenVar = "";
    %>
    < html code
    <input type type = "hidden" name="hidden" vale="<%=hiddenVar %>"
    html ends>
    while in js function you can assign vale to the hidden variable which will ultimately assign value to the JSP variable as follows.
    var str = "value";
    document.form_name.hidden_field_name.value = str.
    hope this hepls.

  • 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?)

  • How to pass javascript variable to jsp function

    i want to check which table header (that is <th> in html )is clicked and based on that a jsp funtion do a query in database and should show records in sorted way according to which column head is clicked.
    Table is created in html.
    My function is
    Vector varray = workcaseid.getWorkcaseId(Long.parseLong(MasterAccountNumber),SelectedColumn);
    <table border="1">
              <th ><label onClick="<%SelectedColumn="workcase_id";%>">Workcase Id</label></th>
              <th><label onClick="<%SelectedColumn="status_id";%>">Status</label></th>
    <tr><td>etc</td></tr>
    </table>

    im using bean for business login, following mvc model,and i think mvc is one of good design practice to use.
    <jsp:useBean id="workcaseid" scope="session"class="beanFiles.SearchWorkcaseId" />
    varray = workcaseid.getWorkcaseId(Long.parseLong(MasterAccountNumber),SelectedColumn);
    just tell me whether it is possible to pass javascript variable to jsp variable or not.i can do it by using hidden input type,using form and submit button.

  • 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 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.

  • Passing struts-tag value to java / javascript variable in JSP

    Hello all,
    Im trying to pass the value got from the struts-tag to the java variable in the Jsp. However Im not able to get the o/p. Can u guys help me on this pls...
    <logic:notEmpty name="TreeBean" property="list">
        <logic:iterate id="Type" name="TreeBean" property="list" indexId="i">
         <br/><bean:write name="Type" />
        </logic:iterate>
    </logic:notEmpty>Here the list can be populated in the jsp page. However i want the values into jsp list. Im not able to populate the same..
    <% List jspList = null;
    %> I want the values into the jspList variable for further processing. Can u guz pls help me on this....

    Which do you want it in?
    A java variable for use in <% scriptlet code %> or a javascript variable for use on the client end?
    scriptlet:
    <jsp:useBean id="TreeBean" type="java.util.List" class="java.util.ArrayList" scope="?????" />
    Having scriptlet code on the page is considered bad coding style.
    What is it you are trying to accomplish by making the value accessible?
    What are you trying to do in java / javascript that can't be done with JSP tags?

  • Sharing JavaScript variables with JSP

    Hello everyone --
    I was pretty smug when I thought that I could store JavaScript variables in a hidden input parameter for the JSP to pick up.
    When I run:
    <script language=javascript>
    if(confirm("Do you really want to delete this user?"))
       document.write("<input type=hidden name=confirmusr value=true>");
    else
       document.write("<input type=hidden name=confirmusr value=false>");
    </script>
    <b>User input was <%= request.getParameterValues("confirmusr") %></b>I get: User input was null
    I thought that at first I needed to escape the " in write(), but that wasn't it. Does anyone know why it seems that JS is not creating that hidden input type? Thanks in advance for any suggestions, Kwj.

    You can do it this way:
    <form name="myForm" etc etc>
    etc
    <input name="confirmUser" type="hidden" value="">
    etc
    <script language="javascript">
    function onClickHandler() {
        if (confirm("Do you really want to delete this turkey?"))
            document.myForm.confirmUser.value = "true";
        else
            document.myForm.confirmUser.value = "false";
        document.myForm.submit();
    </script>
    etc
    <input name="button" type="button" value="Delete Turkey" onClick="onClickHandler()">
    etc
    </form>
    etc etc etc

  • Need a fast answer... passing javascript variable to jsp page (how to use)

    This test application has 3 frames.
    I'm assigning a value "stuff" to a variable ("testfield1") in a javascript function ("getTest") that exists inside an html frame (testpage1.html)
    Then, I click on the "test submit" hypertext link to pass the value of "testfield1" to the JSP frame (testpage2.jsp) by invoking a function ("getData") in "testpage2".
    In function ("getData"), I am passing the variable "testfield1" as a parameter to the "getData" function in "testpage2".
    In "testpage2" - in the ("getData" function) I try to assign the value of the variable "testfield1" to another variable called "testfld1".
    Then, I try to extract the value of "testfld1" into a variable called "tstfld1" in a JSP scriptlet
    ....I.E. [ String tstfld1  = request.getParameter("testfld1");  ]
    But, the value is apparently not passed successfully, as tstfield1 appears to be "null".
    Can anyone explain what I'm doing incorrectly?
    The code for this test app is below...
    ********testpage0 - the parent frame*********
    <HTML>
    <HEAD>
    <TITLE>GlobalView Reports and Trending Menubar</TITLE>
    </HEAD>
    <FRAMESET FRAMEBORDER="0" ROWS="15%,85%">
    <FRAME SRC="testpage0.html" NAME="testhtmlparent">
    <FRAMESET FRAMEBORDER="0" COLS="23%,77%">
    <FRAME SRC="testpage1.html" NAME="testhtml">
    <FRAME SRC="testpage2.jsp" NAME="testjsp">
    </FRAMESET>
    </FRAMESET>
    </HTML>
    *******testpage1.html********
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <html>
         <head><title>testpage1</title>
         <link rel="stylesheet" type="text/css" href="./standard.css">
              <script LANGUAGE="JavaScript">
              parent.frames[2].location = "blank.html";
              function getTest(reportType)
                   testfield1 = "stuff";
                   alert("testpage1.html...testfield1=" + testfield1 + ", reportType=" + reportType);
                   parent.frames[2].location = "testpage2.jsp";
                   parent.frames[2].getData(testfield1);
                   return;
              </script>
         </head>
         <body bgcolor="#FFFFFF" text="#000000">
              <form name="reportRange">
                   <center>
                        <fieldset style="padding: 0.5em" name="customer_box">
                        <table cellpadding="0" cellspacing="0" border="0">
                             <tr class="drophead">
                                  <td valign="top" height="0" ><span class="drophead">
                                       test submit
                                  </td>
                             </tr>
                        </table>
                        </fieldset>
                   </center>
              </form>
         </body>
    </html>
    *******testpage2.jsp*********
    <%@ page language="java" import="java.io.*, java.util.*" errorPage="error.jsp" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <html>
         <head>
         <title>testpage2</title>
         <script language="JavaScript">
              function getData(testfield1)
                   alert("testpage2.jsp...testfield1=" + testfield1);
                   document.pageData.testfld1.value = testfield1;
                   document.pageData.submit();
         </script>
         </head>
         <body>
              <%
                   String error;
              %>
              <div id="HiddenForm">
                   <form name="pageData" method="post" action="testpage2.jsp" target="_self">
                   <input type="hidden" name="testfld1" value="0">
              </form>
              </div>
              <%
                   String tstfld1 = request.getParameter("testfld1");
              %>
              <P> testfld1 = <%= tstfld1 %> </P>
         </body>
    </html>

    parent.frames[2].getData(testfield1); is in testpage1.html
    so in the document.pageData.testfld1.value = testfield1; document = testpage1.html( not testpage2.html)
    modifying the getData to accept the document object, and refering this object to parent.frames[2].document may help you.
    good Luck ....

  • How do i compare value javascript variable with jsp variable

    I have promblem .I have variable that store store the attribute value of column .The colum has more then one value.How to i compare with javascript value .Currently I am using the following method .
    <%String sql_query3 = "SELECT DISTINCT (ir_tran_typ),ir_rea_desc "+
                                              "  FROM intrcd "+
                                              " GROUP BY ir_tran_typ ";
                               System.out.println("trans type"+sql_query3 );           
                                try{
                                    rset = db.execSQL(sql_query3);
                                catch(SQLException e) {
                                    System.err.println("Error in query - intrcd - transaction_main.jsp " +e +" sql " +sql_query3);
                                while(rset.next()== true){
                                    tran_cde = rset.getString("ir_tran_typ");
                                            rea_desc = rset.getString("ir_rea_desc");%>
                                            <%System.out.println("trans type 34 "+tran_cde );%>
                                                 //tran_typ = addElement('<%=tran_cde%>');
                                                 <% }%>
                                      if(obj.value== '<%=tran_cde%>' ){      
    <%                                 String sql_query2 = "SELECT ir_rea_cde,ir_rea_desc"+
                                              "  FROM intrcd"+
                                              " WHERE ir_tran_typ = '"+tran_cde+"' " +
                                                        " ORDER BY ir_rea_cde ";
                               System.out.println("trans type"+ tran_cde);           
                                try{
                                    rset = db.execSQL(sql_query2);
                                catch(SQLException e) {
                                    System.err.println("Error in query - emmast2 - transaction_main.jsp " +e +" sql " +sql_query2);
                                        index = 1;
                                while(rset.next()== true){%>
                                document.all.rea_cde.options[<%=index%>] = new Option(eval('"<%=rset.getString("ir_rea_cde")%>"'));
                                document.all.rea_cde.options[<%=index%>].value = eval('"<%=rset.getString("ir_rea_cde")%>"');
                                document.all.rea_cde.options[<%=index%>].text = eval('"<%=rset.getString("ir_rea_desc")%>"');
    <%                          index++;
                                       }%>
    please replay me soon
    thank you.

    javascript and java do not mix.
    Java code runs, and produces HTML/javascript.
    Java code stops running.
    The page loads in the browser, and it starts up javascript.
    Javascript cannot talk to java and vice versa.
    Your JSP can generate javascript code onto the page to be executed on the client, but they never directly communicate.
    please replay me soongame over dude ;-)

  • Need help to get JS variable from JSP???i have partial soultion

    Hi everyBody
    here a littil desciption about wht i need:
    the user should Input value by (prompt) in javascript, then the value will be assigned to JS variable
    and i need the value which the user input but in JSP
    so i do like this
    <script>
    var gg;
    function getF(){
      gg = prompt("yes","input name"); 
    </script>JSP+JS,, both in same page
    now JSP code
    String newname = "<script>document.writeln(gg)</script>";now the problem is->
    i need pass the newname variable to the method renameTo() which belong to FILE class
    but i face problem with it cuz newname variable will not be assigned, it will execute the statment each time i use newname varible????
    while renameTo() method should take parameter type File.
    i hope i put al the details about my problem
    any help please???

    BalusC:
    i've tried ur way:
    this is the JS function
    <script>
    var userInput;
    function getF(){
    userInput = prompt("yes","input name");
    return userInput;
    </script>and here where i call the JS function and then pass the returned value
    out.print("<a href = index.jsp?'newName=javascript:getF()'><img src = folder.jpeg width = 48 height = 48 /></a>");i got the parameter here
    String newPath = request.getParameter("newName");
    out.print("newnameObject = "+newPath);but it return null????
    any explain???!!!!
    bst rgds
    Edited by: Mr.Carlito on Jan 8, 2008 3:53 AM

  • Using Javascript variable in JSP

    I m setting a variable named btn to the value of the button which was clicked but the problem here is that i m nt getting its value whn i want to set it to a request.setAttribute() method.

    > Yes... nw i get the prob... thanx yaar .... bt cn u
    suggest me wht cn i do fr this situation
    My first suggestion, beyond all others, is to use real words. Your writing is practically unintelligible.
    Please make the extra effort to write out words such as "now", "problem", "thanks", "but", "can", "you", and "for" (I have no idea what "yaar" means). The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership. Also, it will give the appearance that you take your question seriously, which will in turn make your question look more interesting to answer.
    ~

  • How to access javascript variable's value in a jsp tag?

    Is there any way to access the value of a javascript variable in jsp?

    Hi
    by the way your question is ambigous, i understand the question to some extent here i there is a sample code which may be help full to you. As this problem is faced by me when i was developing some dynamic pages in my company.
    <%@ page language="java" %>
    <html>
    <head>
    <script language="JavaScript">
    var i = 10;
    var k = 20;
    </script>
    </head>
    <%
         String Jspi = "";
         Jspi = ("<script>document.write(i);</script>");
         out.println(Jspi);
         Jspi = ("<script>document.write(k);</script>");
         out.println(Jspi);
    %>
    </body>
    </html>
    This will help u out.
    Cheers
    Rambee

  • Getting system Variables

    Hi. I'm creating jsp page, which uses ssl connection. I want to print information of user logged into page, but I can't understand - how to get system variables in JSP page?
    directory httpd.conf file:
    <Files ~ "\.(cgi|shtml|php)$">
    SSLOptions StdEnvVars ExportCertData
    </Files>
    # ExportCertData
    When this option is enabled, additional CGI/SSI environment variables are created: SSL_SERVER_CERT, SSL_CLIENT_CERT and SSL_CLIENT_CERT_CHAINn (with n = 0,1,2,..). These contain the PEM-encoded X.509 Certificates of server and client for the current HTTPS connection and can be used by CGI scripts for deeper Certificate checking. Additionally all other certificates of the client certificate chain are provided, too. This bloats up the environment a little bit which is why you have to use this option to enable it on demand.
    For example, I want to get SSL_CLIENT_CERT variable. How should I do it?

    Did you tried
    System.getProperty("");
    Just check if it works for you.

  • How to pass the javascript variable value to a jsp

    Hi
    I am trying to set a javascript variable with onClick event of a radio button in jsp
    and I am assigning this variable to a hidden property in JSP whic has the corresponding getter an setter method in form.
    But I am not able to retrtieve the value assigned in either form/action .can any body help me in this:
    The code is
    <script language="javascript">
    var jais="";
         function setValue(val)
              jais=val;
         document.o.value=jais;
    </script>
         <html:hidden property="o" value=""/>
    <input type=radio name="1"
                                            value="xyz"
                                                                          onclick="setValue('XYZ')" >
                                            ABC                                        
    and in the correspoding form bean I have
    private String o_val =null;
    public String geto()
    return o_val;
    public void seto(String strs)
    o_val=strs;
    In the action I am trying to access
    by
    1)String j=((form name)form.geto();
    2)String j=request.getParameter("o")
    but with both of them I am getting the value null
    Thanks in Advance

    You need to set the value of the hidden field in your function.
    Setting an unrelated variable will not help.
    function setValue(val)
    document.forms[0].o.value = val;
    also your get/set methods should be getO() and setO().

Maybe you are looking for

  • BP Report

    Dear All, Please if anyone know transaction for BP report and also how to Know who is the user that created the BP. Best Regards, Khairy Soliman

  • Removing Ken Burns effect once photo is on time line

    I am using the lastest version of iMovie, I have made a movie using only photos. All of the photos have the Ken Burn's effect some are ok but other are not. Can the Ken Burn's effect be turned off once images are on the time line?

  • Removing opening window

    I just purchased a new HP Laptop.  I downloaded the current version of Adobe Reader.  When I boot Reader, a menu window appears on top of Reader.  It gives me the choices of signing in or choosing a pdf file.  I do not like this window and I want to

  • Moving iphone sync from one computer to another

    Hi everyone, I am about to switch from one laptop to another & would like to start syncing my iphone 4 on the new laptop. How do I do the transfer? I tried once and the iphone will sync any apps from the laptop to the iphone (none at the moment so it

  • Just got my 3gs yesterday, no service?

    My 16gb 3gs was working when I left the store yesterday (I live in Canada, I'm with Bell) and all of a sudden my phone showed no service. I turned it off/on, that didn't work. I took it to the store where I purchased it, and they put 2 different sim