This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP And Javascript - How to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP And Javascript - How to" Watch "JSP And Javascript - How to" New topic

JSP And Javascript - How to

Harish Tam
Ranch Hand

Joined: Feb 17, 2005
Posts: 71

Hello Everybody,

Though this problem is not occuring in everyday life but would like to get a solution for this or two....

Here is the issue...........

I have a Jsp page with some javascript code in it, actually this is a jsp pop-up, from a main window, what i do is get the form textarea data using javascript opener.document.fomrname.fieldname.value and set that value in a javascript var, now i have a Java scriptlet inside my jsp and want to initialize that javascript var value to a Java variable, hope this is possible.........

If yes then can anybody tell me how this is achieved or is there any other way to to the above task....

Thanks and Regards

SCJP 1.4, SCWCD 1.4
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Harish, I guess it is not possible. You can use html code with Java but, reverse is not possible. I mean you can not use Java code with html.
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
Just extension of Reddy�s answer�
Scripts such as javascripts run with the help of client browser and during execution have no interaction with server side code such as jsp/servlet. Hence it is not possible..

If you interested to pass the values to the server side code, one of the way to achive is to set some hidden html tags, set this hidden tags values from the javascripts, when you submit the page to the server read this hidden tag value can be read (from request object) and assign java(jsp/servelt) variable reverse can also be done. i.,e assign the hidden variable from server side and read it from javascripts�..
[ February 27, 2006: Message edited by: Arun Boraiah ]

Sharing is learning
It is sorta covered in the JavaRanch Style Guide.
subject: JSP And Javascript - How to
Similar Threads
How to pass java script variable to JSP?
"Unterminated <c:out tag" Error
get string values from Request and Session
How to send an Object of name value pairs to another Page