aspose file tools*
The moose likes Servlets and the fly likes Servlets & javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets & javascript" Watch "Servlets & javascript" New topic
Author

Servlets & javascript

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have a servlet which retrieves a string from the database. Can I pass that string to a javascript variable???
That variable is than sent to the client side to do further processing.
Edgar Sanchez
Greenhorn

Joined: Oct 12, 2000
Posts: 21
Try something like this in your web page:
<SCRIPT LANGUAGE="Javascript">
var myJSstring = '<%= myJSPClass.getValue() %>';
var myJSnumber = <%= myOtherJSPClass.getValue() %>;
</SCRIPT>
[This message has been edited by Edgar Sanchez (edited October 22, 2000).]
Prabhu Chandrasekaran
Ranch Hand

Joined: Oct 14, 2000
Posts: 36
Hi,
One of the methods through which you can access java variables in JavaScript in servlets is through hidden variables.
After retreiving the string from the database, put it as a value for a hidden field using the foll. code :
out.println("<input type=hidden name=fieldname value='"+varname+"'>");
You can access the same in JavaScript for client side validations using document.formname.fieldname.value.
I have used the same in many of my servlets.
See if this helps your cause.
Bye.

------------------
S Chandra Mohan
Ranch Hand

Joined: Oct 19, 2000
Posts: 75
hai,
u can take the value of the varialble directly into javascript
like
out.println(" function valchk(){ ");
out.println(" var sampval = " + mservval + " ; ");
.....
or u can directly check like
out.println(" if(document.myhtm.t1.value = '"+mservval+" ) { ");
.
i think this can solve ur problem much
all the best'
bye
mohan

Have a wonderful day and wish u success<p>S Chandra Mohan<br />sc_mohan_us@yahoo.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets & javascript