This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp location

 
apurv suthar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Organization is good. Why would you feel otherwise?
 
apurv suthar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18025
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic