Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes Javacript variables within EL syntax methods invocation 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 "Javacript variables within EL syntax methods invocation" Watch "Javacript variables within EL syntax methods invocation" New topic
Author

Javacript variables within EL syntax methods invocation

Luciano Daher
Greenhorn

Joined: Sep 14, 2012
Posts: 4
Hi Everybody,

I recently got here and I'm already a big fan of yours, not to mention the fact that I bought almost the entire Head First collection.

I've seen some posts here bringing up the opposite, as how to pass a EL param (or whatever) value to a Javascript function.

But the goal here is to do the inversion, that is, pass via Javascript set variable a value to be processed within a Java method set in TLD file.

Did I make myself clear? If so, Is that possible?

Note: I was wondering to accomplish that using Javascript window.location instruction adding a "name=value" par at the end of a URL to be caught within EL param, but this approach hasn't sound pretty good, isn't it?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Luciano Daher wrote:Did I make myself clear? If so, Is that possible?

It is not. JSP executes on the server to create the HTML page to send to the client, where the JavaScript is evaluated and executed. They not only don't run on the same machine, they don't even exist at the same time.

See this article to understand how JSP works and why what you are trying to do is not possible.

Note: I was wondering to accomplish that using Javascript window.location instruction adding a "name=value" par at the end of a URL to be caught within EL param, but this approach hasn't sound pretty good, isn't it?

Not sure what you are actually trying to do. Could you try to explain it a bit more clearly?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Luciano Daher
Greenhorn

Joined: Sep 14, 2012
Posts: 4
Thanks for your reply...

Note: I understand when you said about the .JSP being turned into .JAVA, compiled and then it's returned to the client as a .HTML page when the JSP is requested for the first time, which that makes it impossible to achieve what I want, but anyway...

Just to explain what I was intended to do.

It sounds a little bit silly what I'm trying to do but, lets suppose you have a Footer.jsp to be included via standard action within a Main.jsp page and, using standard action, I'd be able to call Java regular methods within an EL syntax (e.g. ${someMethod(String)}) via TLD configuration file.

To turn this example more interesting, at the Java method signature, I added a String argument to be returned, lets suppose, the current time as a String. To satisfy this particular String argument, I would like to pass to it a Javascript var called "time" which is updated via "window.setInterval()" each 1 second to correspond Clock's second.

I know, it's a stupid example, but I'd like to know whether this is possible to achieve or not.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't understand your example, but the bottom line is that you can certainly generate Javascript code from your JSPs. You just can't execute them while the JSP is running.

So for example you could generate Javascript code which would be executed as soon as your generated page was loaded into the browser. That may or may not be relevant to your example, which as I said didn't make any sense to me.
Luciano Daher
Greenhorn

Joined: Sep 14, 2012
Posts: 4
Thanks Paul as well!

It's now very clear for me. Just to make all what I've said understandable (if it's possible) I was expecting the Container not just transform the JSP into Java code and then compile it, as to interpret the Javascript content within the JSP Code, in special the resultant variable from the function inside "window.setInterval(...)" procedure, and a matter of fact, is the browser job.

This question would get into the list of the silliest questions ever, wouldn't it?

Thanks one more time for the refresh...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Did you read the article I linked to? It makes it clear that HTML and JavaScript in the JSP are not interpreted by the JSP engine at all -- it's just template text.
Luciano Daher
Greenhorn

Joined: Sep 14, 2012
Posts: 4
Hi Bear,

I'd like to thank you both (you and Paul) specially you who was the first guy to remind me the "mechanism" involved on a JSP request. About the article, yes I did. By the way the Head First (Servlets & JSP) illustrates that concept very well.

Thank you one more time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javacript variables within EL syntax methods invocation
 
Similar Threads
how to pass parameter from dispatchto javascript
Returning Parameters from Javascript to Java
<h:selectOneMenu> issue
stylesheet messed up in richfaces JSF page
How to pass jsp values to flash?