This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Make root directory an application folder

 
Rob Berrones
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18092
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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 (//www.myserver.com)
port (80, 8080, 443, etc.)
context (/MyApp)
resource (/jsp/example/filename.jsp)

String them all together and you get: http://www.myserver.com:8080/MyApp/jsp/examples/filename.jsp

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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic