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

Similar Messages

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

  • There should be a way to index an array with an array of indexes or booleans (without a loop)

    Hi, often I would love to index an array with an array of indexes or an array of booleans without having to loop it.  I.e: let the IndexArray function accept an array of indexes instead of discrete indexes.  The output should then be an array of indexes values.  
    Another use case is to index with an array of booleans, so each TRUE element would index the input array and FALSE elements are not indexed.
    arrResult = arrInput[ arrIndexes ];  or
    arrResult = arrInput[ arrVal > 20 ];
    Would this be useful? Possibly it could be implemented in future versions?

    You forgot the link.

  • Display jpeg byte array with JSP !!

    I am new in JSP area so maybe I ask a easy question !!
    First, on the server side:I use a C++ program to stream sequence jpeg data out(FF D8 ~ FF D9).
    Second, on the client side:I use jsp to open a socket and read
    data to a byte array.
    Can anyone tell me how to display the jpeg array on browser one by one ?

    um... like video frames, or just a single image? I wouldn't really use JSP for that, I'd use a servlet, set the content-type to image/jpeg and just write out the bytes. Unless you are talking about displaying the bytes themselves, in which case, a JSP page would be better. If it's video frames, I'm not sure how to have the browser do that, since most no longer support server push.

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

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

  • 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

  • Populating a javascript array with datatable data

    I want to populate a javascript array with datatable data.
    How do I do this?
    I want the javascript array to be populated as the datatable is displayed.
    Doing this way doesn't work.
    <h:dataTable value="#{pmManager.profiles}" var="pmProfile" binding="#{pmManagerUiBean.uiTable}" ">
    <script>
    allProfilenames[index]='#{pmProfile.profileName}';
              alert("index ="+index);
              alert("...1"+allProfilenames[0]);
              alert("...2"+allProfileRes[0]);
              index++;
    </script>
    <h:dataTable>

    In Javascript do something like this:
    document.getElementById('form1:dec_param');
    where form1:dec_param is the id of the component on the page source (html)

  • JSP Array to Javascript function :URGENT HELP

    Hi,
    i have problem in sending array from JSP to Javascript function. if you have any answer please let me know asap.
    Thanks in advance.
    -Priya

    Hi Kurt,
    I have written follow. program . but still I'm getting errors.
    I don't know what I'm doing wrong.
    <HTML>
    <HEAD>
    <SCRIPT>
    function showArray()
         var str = new Array (<%for (int j=0; j<jspstr.length; j++);
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));%>);
         alert ("Total elements received: " + str.length);
         for (j in str)
         alert ("element number " + j + " equals " + str[j]);
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM>
    <%String[] jspstr = {"abc", "def", "ghi", "jkl"};%>
    <SCRIPT>
    showArray();
    </SCRIPT>
    </FORM>
    </BODY>
    </HTML>
    com.ibm.servlet.engine.webapp.WebAppErrorReport: C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:135: Undefined variable or class name: jspstr
    for (int j=0; j<jspstr.length; j++);
    ^
    C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:136: Undefined variable: jspstr
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));
         ^
    C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:136: Undefined variable: j
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));
         ^
    C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:136: Undefined variable: j
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));
         ^
    C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:136: Undefined variable or class name: jspstr
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));
         ^
    5 errors
    Thanks,
    -Priya

  • How to fill a javascript array by a jsp array when the jsp is run

    Hi all,
    The problem i am facing is -- i want to use an javascript array in a function. The records are being fetched by jsp.
    How to fill the vaules in a javascript array, which are retrieved by a jsp array
    Please suggest
    Thanking You

    You can use the code below:
    <input type="button" value="Click Me" onclick="javascript:disp('<%= getString(str) %>')">
    <%!
    public String getString(String str[]){
    String arrElements="";
    for(int i=0;i<str.length;i++) {
    arrElements+=str[i]+",";
    return arrElements.substring(0,arrElements.length()-1);
    %>
    function disp(str) {
    arr = str.split(",");
    alert ("There are "+arr.length+" elements in the array");
    Hope this helps.

  • How use bean of array with tag "jsp:useBean"??

    hi,all
    a bean of array put request with a servlet and forward a jsp page,this jsp use "jsp:useBean" of tag get the bean of array.
    how do for jsp:useBean of tag??
    thx.....

    You can't use an array directly in a jsppage. first u have to write the line <useBean /> through which you can access youtr class
    <jsp:useBean id="email" class="Pack.Email" scope="session" />
    after writing this line you have your class in your hand, you can think of "email" as it is a class object of Email class which is a Bean...
    declare a private array in the Bean and then made method getArray() which will return an array ... then you can use your array in jsp....
    an example of using a class variable in JSp is given below
    public String[] getArray() // note method must be public
    return array;
    now in your jsp page you have to use that class with
    <jsp:useBean id="email" class="Pack.Email" scope="session" />
    and cnow you can use array like this....
    <%
    String[] array=email.getArray();
    for (int i=0; i< array.length;i++ )
    out.println(array]);
    %>
    Does it solve your problem now ?

  • Build an array with 2 values assigned to 1 dimension

    I am wanting to build a 1D array where two values are assigned to each dimension.  For example:
    Index 0 would have a 1 and 4 assigned to it
    Index 1 would have a 2 and 3 assigned to it
    Index 2 would have a 0 and 1 assigned to it.
    Then I can unbundle this arrayand grab the two values for index 0, index 1, etc....  I want to put this array inside a typedef control.  Is this possible?
    Solved!
    Go to Solution.

    Thanks for the replies.  I considered using a cluster and had the typedef control modified to include the cluster.  I may just go back to this method if this is the simplest for the code I am modifiing.
    A 2D array assigns two values i.e. row and column to one number.  I need it the other way around.
    Here is what I am trying to do.  I need to control a rotary valve.  I am using compact filedpoint to control the rotary valve.  The valve requires a pulse (1 then 0) for the rotary valve to move 1 position. If the valve is on channel 1 of the fieldpoint module and I want it to turn to position 2, the I send two pulses to channel 1. 
    My thinking is I will have two values associated per rotary valve... a channel and a pulse value. So for example, valve 0 has a Boolean and a numeric value assigned to it in an array. Although, it doesn't have to be a boolean and a numeric.  it could be 2 numeric values for simplicity.
    I hope this makes sense because without knowing this posting a VI or image is useless.  Its the chicken before the egg thing. :-)

  • Multi-dimensional Arrays in JSP

    Hello,
    i am writing my first lines of JSP Code and need some help. what is up with Multi-dimensional Arrays in JSP? Is it possible in JSP? I tried to realise it like in JavaScript, without success.
    So, please help me :)
    Mark

    Hello,
    i am writing my first lines of JSP Code and need some
    help. what is up with Multi-dimensional Arrays in
    JSP? Is it possible in JSP? I tried to realise it
    like in JavaScript, without success.
    So, please help me :)
    Mark

  • How to get the values of an Array using JSP Tags

    Hey guys,
    I need some help. I've splited a String using
    fn:split(String, delim) where String = "1,2,3,4" and delim is ,
    This method returns an Array of splited Strings. how do i get the values from this array using jsp tags. I don't wanna put java code to achive that.
    Any help would be highly appreciated
    Thanks

    The JSTL forEach tag.
    In fact if all you want to do is iterate over the comma separated list, the forEach tag supports that without having to use the split function.
    <c:set var="list" value="1,2,3,4"/>
    <c:forEach var="num" items="${list}">
      <c:out value="${num}"/>
    </c:forEach>The c:forTokens method will let you do this with delimiters other than a comma, but the forEach tag works well just with the comma-delimited string.

  • Help with parallel arrays of different data types

    Hello all, I am having an issue with parallel arrays. My program requires me to read information from a text file into 4 parallel arrays (2 String and 2 double). My text file needs to look something like this:
    John Johnson
    0000004738294961
    502.67
    1000.000
    Jane Smith
    0000005296847913
    284.51
    1000.000
    ...and so on
    Where the first thing is the name (obviously), an account number, the balance in the account, and the credit limit. I just cant figure out how to read everything into the arrays. We havent learned anything too heavy, and this seems a little too advanced for my class, but I guess we will manage. Any help will be appreciated. Thanks guys.
    Casey

    Man this is a dumb homework assignment. The requirements scream out for a class along the lines of
    public class Account{
      private String name, number;
      private double balance,creditlimit;
       // more code here
    }and then to use a List of Account objects.
    Anyway what's your actual problem. There's nothing very hard about it. A loop. So....
    You should consider posting (formatted) code showing what you have done and where exactly you are stuck.

Maybe you are looking for