This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi
i am having an array of objects in a jsp page.
i want to access that array in a function in javascript in the same jsp page.
could any one please tell me how to do that
regards
thanks.
Are you expecting that this will set a session attribute?? If yes, then I'm afraid you are wrong. You cannot set a session attribute through javascript directly. Session is stored on the server, so you'll have to contact the server to be able to set a session attribute...
In above code CustomFieldDetails is a String of objects which is set in request object.
rammie singh
Ranch Hand
Joined: Mar 26, 2009
Posts: 116
posted
0
Is there any other way we can solve this problem.
i also want to send the selected object to my servletManageUser.java can any body help me.
actually i am very new to this servlet and jsp.....so any simple way will be highly apreciated from my side.
rammie you'll have to make either an AJAX request to the server for that or submit the page. Can you please elaborate what you want to accomplish so that I could, well, write some code for you. I would also like to suggest you that you read a couple of books because it seems that you are very new to Servlets and JSP. That way you can understand things better ...
rammie singh
Ranch Hand
Joined: Mar 26, 2009
Posts: 116
posted
0
Hi ankit
thanks a lot for your support.
actually my main moto is.....
i have a jsp page searchedEmpPage.jsp
in this as it there in code a list of employees is displayed .These employee would be as object which are stored in an array fetchedArrayObject[] as mentioned there in my jsp page.
now i want to select one employee through radio button....and which ever employee(object) is selected through radio button ......that element(object) has to be passed to servlet.
You need to STOP right now and learn how servlets, JSP and HTML work. What you are asking is nonsense. You can't mix Java statements with JavaScript, you can't "call" a servlet without submit a form or making an Ajax request, and you can't communicate with code in the JSP once it's executed.
This has been explained to you in your other posts and you are just wasting everyone's time, including your own, by posting the same mistakes over and over again.
For starters, you might want to read this article to get started on understanding how JSP works. Then find yourself a good book or tutorial.
rammie singh wrote:but what is the way we can put an object in a session in a function in a jsp page.
This is where you are going wrong. Do you want to affect the session as part of the JSP processing before the page gets sent to the browser, or in JavaScript after the page gets sent to the browser?
If the latter (which is what I suspect), then the fact that this is a JSP is completely irrelevant. Once the page gets to the browser, it's just an HTML page like any other.
Did you read the article that I linked to? Did you understand it?
rammie singh
Ranch Hand
Joined: Mar 26, 2009
Posts: 116
posted
0
Hi every body
i am sorry to say that but can i really get the solution of my problem in this forum
well as far as Mr. ankit garg solution is concerned....it is not working......the error is same...the function setVals(i) is not able to access the arrays you have created above. because function loading() is not able to push the values from array fetchedArrayObject[] to created array in javascript.
the same problem i am asking from last three days....that whether it's a javascript function....that is a function defined within tag <script type=text/javascript> ....... </script> of a jsp page or a function defined within the tag <body> ...</body> of a jsp page, how can we acccess a jsp variable within those function directly. and if yes the how.
i don't know if this forum runs to give any solution or just for fun.
i am sorry guys if i made any hard coment.
thanks.
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
JSP/Java runs at server side. JSP/Java generates HTML/CSS/JS output. Server side sends output to client side. Client side runs HTML/CSS/JS.
View the page source in your webbrowser and think once more about it.
To "access" JSP/Java variables in JS, simply let JSP/Java print it to the output as a JS variable!
For the last time, READ THIS ARTICLE. If you are going to ignore the advice and information presented to you, of course you aren't going to learn anything.
rammie singh wrote:i don't know if this forum runs to give any solution or just for fun.
You have been given plenty of information that you seem to be just ignoring. Are you posting for fun or are you actually trying to learn anything?
Lei Guoguo
Greenhorn
Joined: Mar 31, 2009
Posts: 26
posted
0
you can use like this:
I'm a chinese, my english is so bad, I need help. If you want to help me, you can send your question to my e-mail: lgg860911@yahoo.com.cn, I will help you, and improve my english. Thanks everyone.