aspose file tools*
The moose likes JSP and the fly likes Send from JSP via JavaScript to a JBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Send from JSP via JavaScript to a JBean" Watch "Send from JSP via JavaScript to a JBean" New topic
Author

Send from JSP via JavaScript to a JBean

Emil Karlsson
Ranch Hand

Joined: May 23, 2002
Posts: 63
Hi,
I have an jsp-page with a form including two dates. The first date is entered from the user, and when the textbox is 'onBlur' the second date should be calculated and entered automatically. I have made the JBean that calculate the second date, and it works fine, but my problem is that I can't send the first date to the JBean! The JBean takes my date-String if I hardcode the date in the jsp!
Anyone who has an idea what to do?
Some code:

The most above works fine! Everything is OK when I hardcode the String parameter in the setBestDate() method but when I try to put a variable instead of the String, I get a NullpointerException:
/Emil
[ July 08, 2003: Message edited by: Emil Karlsson ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

You cannot call a Javabean from Javascript.
The JSP page is executed on the server in order to render the HTML page to send to the browser. This is the point at which any Java on the page is executed -- including the snippet inside your Javascript function.
The HTML page is sent to the browser where, as a result of user action, your Javascript executes. The bean was never on the client, and has probably long been gone on the server.
If you perform a View Source in your browser, you will see that your Javascript function has no mechanism to call the Javabean, but that the HTML sent to page has the result of calling that bean (on the server) embedded in your page.
What it comes down to is this: you have server-side technology, and you have client-side technology, and you cannot mix the two.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Emil Karlsson
Ranch Hand

Joined: May 23, 2002
Posts: 63
Thanks Bear,
I should have realized that from the start.
But now I will always remember.
Emil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Send from JSP via JavaScript to a JBean