File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Pass java value to javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Pass java value to javascript?" Watch "Pass java value to javascript?" New topic
Author

Pass java value to javascript?

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
I have to access a java value in js from a jsp..

<%
strReferralValue = tempValue + strReferralValue;
%>

How do I access the strReferralValue for a validation
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2551
    
    2

How do I access the strReferralValue for a validation


Is strReferralValue coming from the same page or from the database?
Since you want to do only the validation stuff, there should be no problem in both the above cases. If the variable is on the same page, then validation is straight forward, if its from a database, then you've already validated it before putting it there,isn't it.

Please tell some details about what you are trying to do.


SCJP, SCWCD.
|Asking Good Questions|
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
I am defining the variable in the JSP

<%tempValue = agency.getFltReferralPerecentage(); (This value comes from a different class)
strReferralValue = tempValue + strReferralValue;
%>

I wanted to use the value of strReferralValue in JS to do a validation to check whether the sum of all its values are not more than 100..

I am using struts 2 framework
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

You can;t really pass anything from the JSP to the JavaScript as they run on different machine at different times. But remember that with JSP, you can use Java values to create the template text that becomes the markup (HTML and JavaScript).

For example:

(assumes use of EL not scriptlets)


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Pass java value to javascript?
 
Similar Threads
implicit object "page"
unit testing of singleton classes get methods
How to access out parameters in c++ dll
Struts:How to pass value from action class to jsp?
jsp page not able to call java bean