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

multiple js and jsp

Walter Krawiec
Greenhorn

Joined: Jan 13, 2009
Posts: 20
Dear all,

Can somone tell me why I can't load few *.js scripts from JSP file <head> section?

I've tried but server loads just first file, rest it's skipped.
It's becouse of performance issue?
How I suppose to include few js file without combining them into one file? (one js works fine), is there any method to join them?

thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

Walter Krawiec wrote:I've tried but server loads just first file, rest it's skipped.

The server has nothing whatsoever to do with it. There is no reason on earth that you cannot include multiple script files. I do it all the time.

And it certainly has nothing to do with JSP, since only an HTML file is sent to the browser.

It's most likely that your script file URLs are invalid.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Walter Krawiec
Greenhorn

Joined: Jan 13, 2009
Posts: 20
Bear Bibeault wrote:
It's most likely that your script file URLs are invalid.


It's valid i tried to use firebug and load each js file and it's working fine, but if I want to attach more files it's loading just one....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

Code?
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Walter Krawiec wrote:Can somone tell me why I can't load few *.js scripts from JSP file <head> section?

You can use <jsp:include page="" /> to include as many files as you'd like. If you want to include 5 .js files, then use 5 includes.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

Max Rahder wrote:
Walter Krawiec wrote:Can somone tell me why I can't load few *.js scripts from JSP file <head> section?

You can use <jsp:include page="" /> to include as many files as you'd like. If you want to include 5 .js files, then use 5 includes.

Not a good idea. In fact, it's a pretty bad one. That will cause the JS to be included in-line and prevent any caching by the browser.

Once again, there is nothing short of a code error that can cause this to happen. Fix the code rather than looking for weird work-arounds.
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Maybe I misunderstand the OP. If he needs to dynamically specify the page to include, I don't know how else you'd do it. If he's just doing a standard <script src=, then it's not a JSP issue at all.>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

I think you misunderstood him.

I think that the only JSP-ness to this issue is that the URL's to the JS scripts are likely invalid, probably due to not using the context path properly, as is usual in these cases.

But until the OP posts his code, we can't know.
Walter Krawiec
Greenhorn

Joined: Jan 13, 2009
Posts: 20
Bear Bibeault wrote:I think you misunderstood him.

I think that the only JSP-ness to this issue is that the URL's to the JS scripts are likely invalid, probably due to not using the context path properly, as is usual in these cases.

But until the OP posts his code, we can't know.


normally I'm adding few files inside <head> section:


it's working for first file in queue, i've tried to swap between these file and each file was loaded properly but still just first one..


Walter Krawiec
Greenhorn

Joined: Jan 13, 2009
Posts: 20
I have tried few things, but without luck.

1. I squeezed all scripts into one js file, after loading page file is loaded but in firebug there is an error: "" is undefined".

2. Second option is to load js files by using this option works for one js file. if you try to load next one it will be skipped.

I do not understand where is the issue, normally Glassfish loads few files automatically for particular components like: dropdown menu, accordion etc...,

Can somone enlight me?

cheers
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
if your first js file have some syntax problem OR any type of problem,error then probably your other files will not be loaded OR if they will be loaded then they will show error.
so better if you check your first js file OR you can do 1 more thing change the order of file which you are using i mean put first js in last.
It is also a good practice to put all .js files in last of the jsp page if you are using many js files because when your page will be loaded on web browser first it will load all .js files after that your view will be displayed. In this case user have to wait a little long.so better provide view & then js should be loaded. This should be used if your page is not using js files initially OR if this approach not affecting your business logic.


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

Your <script> tags are self-closed. That is invalid in most browsers.

Use markup such as:
Mart Hansson
Greenhorn

Joined: Oct 08, 2010
Posts: 1

the way you import multiple css/js-files is:

of course modify it to suite your needs.
the -part tells the browser where the files are relative to where they are deployed. If you don't do this and the application is moved from one location to another the paths wont be correct and the browser won't find the files.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

Mart Hansson wrote:the -part

But, of course, this should be done with the EL and not discredited scriptlet expressions as in this example.

The EL equivalent: ${pageContext.request.contextPath}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple js and jsp