aspose file tools*
The moose likes JSP and the fly likes is it good to use a path inside jsp starting with WEB-INF? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "is it good to use a path inside jsp starting with WEB-INF?" Watch "is it good to use a path inside jsp starting with WEB-INF?" New topic
Author

is it good to use a path inside jsp starting with WEB-INF?

Tiya Khambadkone
Ranch Hand

Joined: Sep 15, 2011
Posts: 52
I said urgent because I have this issue and needs to be fixed immediately.

I have a jsp which is in some folder outside WEB-INF. This is my project structure and I can not change it.
Now this jsp contains something like :

<%@ include file= "../something.inc"

This file .inc resides inside WEB-INF/somefolder/.

I get 'included file not found' exception.

So is it a good idea to give the path like :
<%@ include file= "/WEB-INF/somefolder/something.inc"

OR

I should just copy something.inc file to the location where my jsp is orginally trying to find ?


This will be deployed on a production environment. So I hope it does not create any problem.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

Using the path starting with "/WEB-INF" is vastly preferred over using page-relative paths starting with "..".

Do not just start copying files around. That'd just likely lead to a big old mess!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tiya Khambadkone
Ranch Hand

Joined: Sep 15, 2011
Posts: 52
Thanks for the quick response and I will make sure next time I don't use uregent,etc. words.

Why is WEB-INF usage preferred ?

Isn't using relative path better than absolute ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

Tiya Khambadkone wrote:Isn't using relative path better than absolute ?

The path starting with "/WEB-INF'" is relative. An absolute path starts with the protocol (e.g. http: or https:)

But there are a number of types of relative paths, each of which may be required or preferred in different situations:

  • server-relative path, starts with the context path. Preferred for URLs initiated from the browser (e.g. images, script files, stylesheets, form actions, and so on).
  • context-relative path, starts with "/" and is relative to the context base. The path starting with "/WEB-INF" is a good example. Preferred for paths used on the server for resources within the same web app (includes, forwards, etc).
  • page-relative path, relative to the current URL path. Anything that starts with "." or ".." or a file or folder name relative to the current path. These are fragile because they are relative to something that may change (current path) and should not be used in Java web applications. (The one exception is paths within stylesheets which cannot be easily prefixed programmatically with the context path.)


  • The path starting with ".." is a page-relative path and should not be used.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61764
        
      67

    This comes up enough that I've gone ahead and created a new entry in the JSP FAQ to cover it.
    Tiya Khambadkone
    Ranch Hand

    Joined: Sep 15, 2011
    Posts: 52
    Thanks for the reply. Highly appreciated .
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: is it good to use a path inside jsp starting with WEB-INF?