Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Make root directory an application folder

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Here's the low-down:

I inherited a beast of an application. I am trying to make it more manageable, but in order to do that, I need to break it apart.

In my C:\Tomcat 6.0\webapps\MyApp project, I need to do some absolute references due to folder jumping and global includes. (long story)

I have a file in C:\Tomcat 6.0\webapps\MyApp\jsp\example\filename.jsp an example link in this file would be

/includes/headers/header.jsp. (which makes the path: C:\Tomcat 6.0\webapps\includes\headers\header.jsp)

I need the path to be:
C:\Tomcat 6.0\webapps\MyApp\includes\headers\header.jsp

In other words, any files in the MyApp folder need to have MyApp be its root, not webapps. I've tried everything, and nothing has worked. please help me.

I know this probably isn't explained very well, but I'm new to this and don't really know what I'm doing.
Saloon Keeper
Posts: 24898
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Rob. I sing my old song, for your new ears:

A file server is not a web server!

A J2EE webapplication server is a service that when presented with a URL and related information will digest it, (usually) take some action, then return a response. In certain cases, that response will be to search a web application's resources and copy one back to the client, but that's not the same thing as being a file server. For example, you can't use an OS "fopen" call on a web server the same way you can with a fileserver's shared files and directories.

Each web application has a URL context. That's the part of the URL that allows Tomcat to determine which of the webapps deployed in the tomcat server to send the URL request to. There's a default context (the root context), located at "/", which is what you'll invoke if you don't specify a more specific context (such as /myapp).

webapp resource references are done relative to the webapp's WAR root. So instead of C:\Tomcat 6.0\webapps\MyApp\jsp\example\filename.jsp, what you'd actually specify is a path of /jsp/example/filename.jsp. Just as a side note, It's better to use forward slashes in pathnames under Java, and doubly so in URLs, Java or otherwise.

Now the actual Uniform Resource Locator (URL) is made up of the following parts:

protocol (http/https)
server/domain name (//
port (80, 8080, 443, etc.)
context (/MyApp)
resource (/jsp/example/filename.jsp)

String them all together and you get:

And because it's a JSP, Tomcat won't actually copy the resource to the client, but will instead compile it into java code, execute the java code, and return the output.

However, there's one real annoyance. URLs can be absolute or relative, just like file paths. Except that an absolute URL is absolute relative to the server, not to the webapp. Meaning that a URL of "http:/filename.jsp" would be passed to the default webapp, not to the webapp that the reference came from.

There's an HTML tag that can be used to select an alternate URL base for relative URL references on a returned page. Not all J2EE environments have a place for it, though.

The other alternative is to encode the JSP URL with dynamic content that gets the application context and inserts it into the "absolute" URL so that the returned URL is "http:/MyApp/filename.jsp".
Rob Berrones
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick reply. I'm a front end guy, so I'm familiar with how it all works, I just needed to know if I was missing a server configuration somewhere. The solutions posed by you won't work for this particular project. They left me in a cluster. Thanks again for the help.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic