0

There is a header content which comes from a external url(say http://sample.com/header.html). I want to include this header in my jsp file that actually I can see this header in my jsp page. When I run my jsp page this header url should be shown on the top of my jsp page.

I appreciate if you can help me with that!

<%@ page contentType="text/html; charset=ISO-8859-1"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    </head>
        <body>
            <c:import url="https://www.google.com/?gws_rd=ssl"  /> 
         </body>

</html>
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Shab
  • 5
  • 8

1 Answers1

1

You need to add JSTL taglib in your path,

 <%@ page contentType="text/html; charset=ISO-8859-1"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

To import content from an external URL to a JSP, JSTL provides tag.

For instance,

 <c:import url="http://external.com/some/fragment.html" />

will add the content from the url specified to JSP at the request time. See the Answer From BalusC

update: You can try with <iframe> if you looking for embedding google page in your header (as if required by you). See the code sample below,

<iframe src="http://www.google.com" style="width: 90%; height: 300px"
scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0">
</iframe>

Hope this help you.

Community
  • 1
  • 1
Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
  • but it does not bring the css...right? I want to read the complete css – Shab Mar 07 '16 at 16:05
  • It's not like that, you can the valid URL whatever it is. Try and let me know. – Vinoth Krishnan Mar 07 '16 at 16:46
  • I added a simple jsp code in my original question that contains your code...you can try it and see the css does not come through – Shab Mar 07 '16 at 18:52
  • Please let me know if you know what the issue is. Thanks! – Shab Mar 08 '16 at 16:16
  • No, I do not see any error. Did you try the code that I added to see what I mean? – Shab Mar 08 '16 at 17:38
  • If it returns a complete `` document and/or is context-dependent, then you really have to use ` – Vinoth Krishnan Mar 09 '16 at 05:40
  • iframe is not really what I want. I have used cfinclude in coldfusion code and include in PHP to use a url as the header of my pages and another url as the footer of my pages. I am trying to do the same thing in JSP but include does not work like it does in coldfusion and PHP. That's why I used import, but still I have problem including that url as my header/footer in my JSP page. – Shab Mar 09 '16 at 13:54
  • The `` works on external URLs (thus, resources in a completely different webapp, but those have to be publicly accessible; i.e. you have got to see the desired include content already when copy-pasting the URL in browser's address bar). See [Details](http://stackoverflow.com/questions/19162111/how-to-load-html-page-which-is-outside-application-context-using-jsp-include-or#19184605) – Vinoth Krishnan Mar 09 '16 at 14:01
  • I have tested the code in my original question with a publicly accessible url as the header/footer instead of using google url (which I cannot share here) but It does not work...If you try the code in my original question with a publicly shared url, you see what I mean. Thanks! – Shab Mar 09 '16 at 16:13