• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple js and jsp

 
Walter Krawiec
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Walter Krawiec
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code?
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your <script> tags are self-closed. That is invalid in most browsers.

Use markup such as:
 
Mart Hansson
Greenhorn
Posts: 1
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic