File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to use jsp in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to use jsp in javascript" Watch "How to use jsp in javascript" New topic
Author

How to use jsp in javascript

santbir singh
Greenhorn

Joined: Aug 25, 2012
Posts: 6
Hello everyone

I want to include navigation bar in html page which should work in all browsers. To include navigation bar i am using following methods.

I want to use jsp tag(include tag) in javascript beccause by using this way i can include html page in anothe html page. I could do that in html by Iframe or .load() method of jquery but these method have some errors
like in iframe i can't use navigation bar because in iframe having size of 1000px and 40px i am unable to see submenu of navigation bar. On other hand, if i am using jquery then .load() method working only in firefox rather than others like opera, IE, chrome. Also tell me if i will use jsp tag in javascript then it will run without tomcat server or not?

So please help me anyone.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
I'm not clear on what you're trying to do, particularly on the "JSP in JavaScript" concept. The "include HTML page in another HTML page" concept dubious; are you maybe talking about page snippets? Can you give an example of how you envision that work?

Also, JSP code runs on the server (which, yes, is required), whereas JavaScript runs in the browser.


Ping & DNS - updated with new look and Ping home screen widget
santbir singh
Greenhorn

Joined: Aug 25, 2012
Posts: 6
I am sorry if you didn't understand what i mean. so i am going explain. Please first read this two files

this is home page index.jsp




Now this is next file i am sending to you is navigationbar.jsp (I could make it html file but didn't becuase i was working on tomcat)



css style sheet (component.css)



css style sheet (style.css)



css style sheet (Navibar.css)



These style sheets are also attached in attachement


Now you can see that i have include one file(navigationbar.jsp) in other file (index.jsp) with jsp scripltets ( <%@include file="navigationbar.jsp" %> )
So what i was asking is that is it possible to use this code in html pages using javascript ? Becuase i want to execute these web pages(by saving as .html) on non tomcat server(non java server).

i also used iframe in Html but prooved useless (because submenu will not be visible if we set the iframe size width=1000px and height=40px).
i also used jquery (.load() ) but this was also useless (because it is working only on firefox only)

Now i am looking if it is posiible to use jsp tag(<%@include file="navigationbar.jsp" %>) in html with the help of javascript.

you will not be able to see the header and footer section becuase i didn't sent those files(header.jsp , about.html, footer.jsp)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

No. You cannot use JSP include for this.

You can use AJax to fetch HTML fragments and dynamically insert them into the DOM.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
santbir singh
Greenhorn

Joined: Aug 25, 2012
Posts: 6
could you give any example if you have or any link where i can read about html inclusion with ajax ?
please
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

AJax is hard to get right without help, so it's recommended to use a library such as jQuery to help.

With jQuery, it's as easy as:
where parent is the id of the DOM element into which the fragment will be inserted, and /path-to-resource is the server-relative URL to the server-side resource that will produce the fragment.
santbir singh
Greenhorn

Joined: Aug 25, 2012
Posts: 6
i all ready used jquery but the page is working only in firefox but not working in all other browser
I want to include b.html into index.html . I am sending you code
please check the following code :-

code for index.html is following


No this is file b.htm to be included in index.html



i don't know where i am making mistake
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

You cannot include a full HTML page (complete with <HTML> tag) inside another. The portion to be included must be a fragment that's valid to place in the target location.
Alex Pi
Greenhorn

Joined: Jan 08, 2013
Posts: 17

navigationbar.jsp
Please, remove <html> </html> and others tags, because when you making including navigationbar.jsp you receive nested <html><html></html></html> tags and so on... It's wrong. And don't confuse JSP with JavaScript.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use jsp in javascript
 
Similar Threads
How do you include a JSP onload?
Problem witn Request Dispatcher..
Problem in Include a url in IE "Access denied"
netui tag
Problem witn Request Dispatcher..