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!
how do I get an array from javascript into java
Collapse
X
-
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").Originally posted by mariazHello, 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 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.Originally posted by r035198xI'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
-
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.
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.Originally posted by mariazI just need to pass the values of the javascript array to my java file.
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
-
[QUOTE=pronerd]Please do not cross post the same question in multiple forums.
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?Originally posted by mariazI 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.Comment
-
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
-
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?Originally posted by mariazI 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?
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
-
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
-
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...Originally posted by mariazYou'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
Comment