aspose file tools*
The moose likes JSP and the fly likes jsp location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp location" Watch "jsp location" New topic
Author

jsp location

apurv suthar
Ranch Hand

Joined: Feb 05, 2012
Posts: 35
I want to know is it good idea to put jsp pages in different directories? Like , putting all admin pages in '/admin' directory , & User pages in '/User' directory ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Organization is good. Why would you feel otherwise?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
apurv suthar
Ranch Hand

Joined: Feb 05, 2012
Posts: 35
Bear Bibeault wrote:It'a a rather poor practice. It means up in the parent folder; which makes it a page-relative URL. Very fragile.

The URL should not be page relative -- it should start with a / that represents the context root.


Mansukhdeep Thind wrote:

When you write ../view.jsp you are instructing the current jsp to include a file by the name of view.jsp located in a directory that is one level up from the directory in which your current jsp is located.


From reading above quotes I illustrate that making directories can cause problems .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Nothing in those quotes says that it's bad to use folders; they say that it's a poor practice to use page-relative URLs.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

One very good reason for using directories is that if you are using the built-in security system, the directory can server as a security context for the role pattern-matcher. In other words, you can ease the job of keeping non-admin users from using admin functions by placing the admin pages in their own directory and setting a web.xml patter such as "/admin/*" permitting only users with the administrator role to access them.

It's also generally good since in large apps, it's a lot easier to both locate a given resource and to determine what its adjunct resources are if they're grouped together (in directories).

I have nothing against relative URLs myself, as long as you don't try to use them in inappropriate places where they might end up referring to the wrong location (this is most common when the resource is included in some other resource, then re-used in a completely different resource in a different location).

Absolute URLs have their own issues, since you can't easily code them in general J2EE webapps without hard-coding the (alleged) deployment context into the URL. Some frameworks, such as JSF, allow for that by permitting "absolute" URLs to root from the base of the webapp itself, but raw J2EE does not.


Customer surveys are for companies who didn't pay proper attention to begin with.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Tim Holloway wrote:Absolute URLs have their own issues, since you can't easily code them in general J2EE webapps without hard-coding the (alleged) deployment context into the URL. Some frameworks, such as JSF, allow for that by permitting "absolute" URLs to root from the base of the webapp itself, but raw J2EE does not.

No one said to use absolute paths. Those are worse than page-relative paths.

The JspFaq outlines how to use server-relative URLs in a manner that requires no hard-coding, and have none of the problems of page-relative URLs, which are fragile and to be avoided.

There's also a FAQ entry describing the various types of relative and absolute paths.
apurv suthar
Ranch Hand

Joined: Feb 05, 2012
Posts: 35
Tim Holloway wrote:
I have nothing against relative URLs myself, as long as you don't try to use them in inappropriate places where they might end up referring to the wrong location (this is most common when the resource is included in some other resource, then re-used in a completely different resource in a different location).

Absolute URLs have their own issues, since you can't easily code them in general J2EE webapps without hard-coding the (alleged) deployment context into the URL. Some frameworks, such as JSF, allow for that by permitting "absolute" URLs to root from the base of the webapp itself, but raw J2EE does not.

This is exactly what I was facing while using relative URLs in inappropriate places.
Bear Bibeault wrote:
The JspFaq outlines how to use server-relative URLs in a manner that requires no hard-coding, and have none of the problems of page-relative URLs, which are fragile and to be avoided.


& JspFaq solves my confusion for relative and absolute paths.
Thanks Tim & Bear :thumbup:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp location