Two Laptop Bag*
The moose likes JSP and the fly likes calling pop-up JavaScript calendar from JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "calling pop-up JavaScript calendar from JSP page" Watch "calling pop-up JavaScript calendar from JSP page" New topic
Author

calling pop-up JavaScript calendar from JSP page

Samantha Simon
Greenhorn

Joined: May 24, 2011
Posts: 14
Hi,

I'm new to Java and to JavaRanch, and am creating a JSP administration page for a website. I am using the jscalendar-1.0 DHTML pop up calendar on this page.

When my page didn't have any JSP code on it, and just HTML, I saved the file as a .html file, and the pop up calendar worked perfectly. But as soon as I saved the same file with .jsp extension, it stopped working.

When I open the JSP page in my IE browser, I get two warnings. One that says "Expected Identifier", and one - "Calendar is undefined".

Here is how I called the files for the calendar on my JSP admin page:



Is something wrong with this? Do the pages need to be called differently from JSP pages?

I'd appreciate any advice or pointers,

Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Do a View Source of the JSP page after it has been delivered to the browser. How does it differ from the HTML version that worked?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Did the URL of the page change in any way other than changing html to jsp?

My first guess would be that the relative javascript files are not being loaded - which says to me either
- the jsp and the html file are in different folders
- you are accessing a servlet and forwarding to the jsp. In which case it will look for resources relative to the servlet URL.

Samantha Simon
Greenhorn

Joined: May 24, 2011
Posts: 14
Hi,

Thanks so much for trying to help me out!

The view source doesn't show any difference in the URLs. It shows some JSP code that the .html file doesn't show, but the files called look the same...

The URL of the .jsp page is no different than the URL of the .html page. Except for the extension, of course.

The JS files being called, are in a separate folder within the same folder as the .jsp and .html files are located.

Stefan, what do you mean by this sentence - "- you are accessing a servlet and forwarding to the jsp. In which case it will look for resources relative to the servlet URL."? I'm really new to programming, so I need extra simplified wording and explanations.

Thank you so much! If anyone has any ideas of how I'd solve this problem, please let me know...
Samantha Simon
Greenhorn

Joined: May 24, 2011
Posts: 14
Hi!

I'm not sure what the problem was. Probably something to do with how my files were set up in my directory. But switching from using static html tags to call the JS pages, to including the pages with JSP tags, solved the problem.

Here's what I swapped the html calls for. (Just in case someone else has my problem, too, one day):



And it worked!

Thanks for your suggestions and help,

Samantha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

While it may be working, it is not a good solution for others to emulate as it will prevent the JS files from being properly cached. The correct solution is to use the correct URLs with <script> tags.
Samantha Simon
Greenhorn

Joined: May 24, 2011
Posts: 14
Here is my file structure. Maybe someone can help me get the right url... (And anyways, why would the URL be different than when I wrote them on the HTML pages?)

Folder1\jscalendar-1.0\(and here the files called from the JSP page)
Folder1\JSP file

Are my URLs correct for this structure?

Thanks so much for the input. I really appreciate it.

Samantha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Using include is wrong, you should be using <script. tags with proper URLs that start with the context path.

E.g. assuming Folder1 (not a great choice of name) is in the app's root folder:



 
It is sorta covered in the JavaRanch Style Guide.
 
subject: calling pop-up JavaScript calendar from JSP page
 
Similar Threads
Jquery function is not working
prototype framework with ajax in struts 2 'jsp
relative path confusion
prototype framework with ajax that is using struts 2 in jsp
JSF page Declarations