my dog learned polymorphism*
The moose likes JSP and the fly likes include file in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "include file in jsp" Watch "include file in jsp" New topic
Author

include file in jsp

ramu somu
Greenhorn

Joined: Oct 12, 2011
Posts: 20
How to include html file which is in static location in a jsp file



but getting error as The requested resource (/static/pjt/html/firstPage.htm) is not available
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

That's the way. You just need to give it the right URL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mary Chellapa
Ranch Hand

Joined: Jul 26, 2011
Posts: 93
And you need to put it in double quotes
and make sure the location of htm to be included is correct


Mary
Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

Use "file" attribute instead of "page":
<%@ include file="" %>

page attribute is for jsp standard action include:
<jsp:include page="" />


Piyush
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Piyush Joshi wrote:Use "file" attribute instead of "page":
<%@ include file="" %>

page attribute is for jsp standard action include:
<jsp:include page="" />


Oops! That's right! Good catch.
ramu somu
Greenhorn

Joined: Oct 12, 2011
Posts: 20
The path of html file is correct but it is not being loaded from the static folder in the jsp page

Can anyone say me if it is possible to load and am I doing the correct process
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Then the path can't be correct.
ramu somu
Greenhorn

Joined: Oct 12, 2011
Posts: 20
Bear Bibeault wrote:Then the path can't be correct.



The path is right. I created a hyperlink in the jsp page with the same path and able to re-direct when click on the link
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Is you app deployed as the root web app?

If not, then it is definitely not right. A hyperlink needs to start with the context path, the include path does not. They'll be different except for when a web app is deployed as the root web app.

Insisting that it's right when it's not is not going to help you any. If it were right, it'd be working.
ramu somu
Greenhorn

Joined: Oct 12, 2011
Posts: 20
Bear Bibeault wrote:Is you app deployed as the root web app?

If not, then it is definitely not right. A hyperlink needs to start with the context path, the include path does not. They'll be different except for when a web app is deployed as the root web app.

Insisting that it's right when it's not is not going to help you any. If it were right, it'd be working.



yes, It is deployed as root.war folder
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

OK, so now it's time for you to show us the folder structure where the file is stored and the paths you are using to access it. Does the path work when you type it into the broser address bar?
ramu somu
Greenhorn

Joined: Oct 12, 2011
Posts: 20
Bear Bibeault wrote:OK, so now it's time for you to show us the folder structure where the file is stored and the paths you are using to access it. Does the path work when you type it into the broser address bar?



the Html file that I have created is in ROOT.war\static\pages\html and path that I am using to access is

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Two things:
  • /static<%=request.getContextPath()%> is definitely wrong -- /static and the context path? What's that all about?
  • Java scriptlets? In 2011? Really? Use the EL: ${pageContext.request.contextPath}
  • ramu somu
    Greenhorn

    Joined: Oct 12, 2011
    Posts: 20
    Bear Bibeault wrote:Two things:
  • /static<%=request.getContextPath()%> is definitely wrong -- /static and the context path? What's that all about?
  • Java scriptlets? In 2011? Really? Use the EL: ${pageContext.request.contextPath}


  • Can you say me the path how to include in jsp file

    inplace of scriplet I have to replace with el
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61606
        
      67

    When creating a client-side resource reference (images, css, scripts, etc), you start it with the context path. Fo example:



    When creating server-side references (include, forwards) the context path is not included.
    ramu somu
    Greenhorn

    Joined: Oct 12, 2011
    Posts: 20


    Then how should I include the html page which tag do I have to use to include the html page which is in static folder in the jsp page
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: include file in jsp