how do I get an array from javascript into java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mariaz
    New Member
    • Mar 2008
    • 11

    how do I get an array from javascript into java

    Hello, I have an array in a javascript file, and I want to pass its values into an array in java. Does anyone know how can I do this?My project is jsf but I am using a javascript file to get data from an xml page and save them into an array (the array I am talking about), and I want this array to pass into the java file in order to edit it in my bean.Thank you in advance!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by mariaz
    Hello, I have an array in a javascript file, and I want to pass its values into an array in java. Does anyone know how can I do this?My project is jsf but I am using a javascript file to get data from an xml page and save them into an array (the array I am talking about), and I want this array to pass into the java file in order to edit it in my bean.Thank you in advance!
    I've never used JSF but I know that in JSP, if you have a parameter with multiple values (read array) you can get the values into an array using request.getPara meterValues("pa rameterName").

    Comment

    • mariaz
      New Member
      • Mar 2008
      • 11

      #3
      Originally posted by r035198x
      I've never used JSF but I know that in JSP, if you have a parameter with multiple values (read array) you can get the values into an array using request.getPara meterValues("pa rameterName").
      I tried using the request.getPara meterValues in the java file but it doesn't recognize it. I don't know how much of a difference makes the fact that it is in jsf. I just need to pass the values of the javascript array to a java file.

      Comment

      • pronerd
        Recognized Expert Contributor
        • Nov 2006
        • 392

        #4
        Please do not cross post the same question in multiple forums.

        [QUOTE=mariaz]I tried using the request.getPara meterValues in the java file but it doesn't recognize it. /QUOTE]
        Asking people to help debug code is not really productive if you do not post the code in question. Can you post the JavaScript that is sending the request, and the Java code reading it? Please use code tags to do so.



        Originally posted by mariaz
        I just need to pass the values of the javascript array to my java file.
        What is your Java file? Where is it running? Java and JavaScript are completely un-related they can not pass values directly to each other.

        If your file is a servlet then you would need to send the elements in the array as parameters in a GET or POST request. Then use the HttpServletRequ est object's getParameterVal ues() or getParameter() methods to read them.

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          [QUOTE=pronerd]Please do not cross post the same question in multiple forums.

          Originally posted by mariaz
          I tried using the request.getPara meterValues in the java file but it doesn't recognize it. /QUOTE]
          Asking people to help debug code is not really productive if you do not post the code in question. Can you post the JavaScript that is sending the request, and the Java code reading it? Please use code tags to do so.




          What is your Java file? Where is it running? Java and JavaScript are completely un-related they can not pass values directly to each other.

          If your file is a servlet then you would need to send the elements in the array as parameters in a GET or POST request. Then use the HttpServletRequ est object's getParameterVal ues() or getParameter() methods to read them.
          I agree the original poster needs to learn how to ask a question. So far it has just been too vague, with talk of a "Java file". Applet? Servlet? What? And there may well be a much better solution that doesn't involve JavaScript at all, but since the original poster hasn't defined the problem he is trying to solve, we'll never know, will we?

          Comment

          • mariaz
            New Member
            • Mar 2008
            • 11

            #6
            I said in my original post that my project is jsf, so the java file I am talking about is a javabean file.From what I have been searching today, I found out that there is a way to create a SAX parser with java and this is possible in jsf projects, but I am not sure. So maybe I really don't need to use javascript at all. Is this true?

            Comment

            • BigDaddyLH
              Recognized Expert Top Contributor
              • Dec 2007
              • 1216

              #7
              Originally posted by mariaz
              I said in my original post that my project is jsf, so the java file I am talking about is a javabean file.From what I have been searching today, I found out that there is a way to create a SAX parser with java and this is possible in jsf projects, but I am not sure. So maybe I really don't need to use javascript at all. Is this true?
              My fault, I missed your menion of JSF (maybe because it was lowercase). As for parsing XML in Java, haven't you noticed all those XML config files you have to create for your web app? Java must be able to parse them, no?

              I still think the best way to approach this is if you explain the details. Where is this XML file? On the server? Remember, it's always better to explain the context rather than directly diving into the details.

              Comment

              • mariaz
                New Member
                • Mar 2008
                • 11

                #8
                You're right, I must write more details. The xml page whose data I want to take is online (actually it is a feed of a website, so its data constantly refresh). That is why I need a way of parsing the xml page through its url and not through its location on a computer. I will look into the suggestion you made, thank you, and if anything else comes to mind I would appreciate it if you could inform me!

                Comment

                • BigDaddyLH
                  Recognized Expert Top Contributor
                  • Dec 2007
                  • 1216

                  #9
                  Originally posted by mariaz
                  You're right, I must write more details. The xml page whose data I want to take is online (actually it is a feed of a website, so its data constantly refresh). That is why I need a way of parsing the xml page through its url and not through its location on a computer. I will look into the suggestion you made, thank you, and if anything else comes to mind I would appreciate it if you could inform me!
                  That fact that you have the URL of a XML document versus a File path makes little difference. There are lots of ways of parsing/accessing XML data. Too many: SAX, DOM, StAX, TrAX, JAXB, etc...

                  Comment

                  • mariaz
                    New Member
                    • Mar 2008
                    • 11

                    #10
                    Thank you very much!I will google the keywords you mentioned and hope to figure it out!

                    Comment

                    Working...