You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Josh Gooding <jo...@gmail.com> on 2012/10/02 20:55:50 UTC
Question on Contexts and resource pathing
Hey group,
I managed to get our company upgraded from Tomcat 5.5 to Tomcat 7, so now
we are on the right track, mostly. Interesting enough I've been fighting
with some pathing issues here, and I am getting frustrated beyond just
losing more hair. The application that I have has an extremely antiquated
deployment method of zipping, rsyncing, unzipping, and restarting the
tomcat server. Another team member and I are trying to fix this issue, and
have gotten war files building, but something interesting happens during
the deployment of the war file. It expands perfectly, and serves almost
like it is supposed to, however when the application is zipped up and
deployed out under $CATALINA_HOME/webapps/ROOT all links to all css /
styles / links to graphics work. (i.e. - all referenced as
/graphics/foo.png or /styles.bar.css). The problem is that the minute I
change the webapp's deploying location by changing the war name, none of
the links work unless I prepend a " .. " or use the JSP EL to the beginning
of the path, so the references are then ../graphics/foo.png or
/warName/graphics/foo.png, etc.
I should be able to build the war to any name I want and still have all of
the links work, even if they are referenced like:
<link rel="stylesheet" type="text/css" href="/default.css" /> NOT ~> <link
rel="stylesheet" type="text/css"
href="${pageContext.request.getContext}/default.css" /> or ../default.css
Obviously there is something that I am missing, but I am not sure as to
what. I shouldn't have to do a S&R on code each time I want to deploy this
code base as a different application someplace else.
Any help or ideas would be greatly appreciated.
As always, warmest regards,
- Josh
Here is my context.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://connection/DBName"
connectionName="shhhh"
connectionPassword="1ts4S3cr3T!!!"
userTable="TomcatUsers"
userNameCol="UserID"
userCredCol="Password"
userRoleTable="TomcatUserRoles"
roleNameCol="RoleID"
digest="MD5"/>
<Manager className="org.apache.catalina.session.PersistentManager"
saveOnRestart="true"
distributable="true">
<Store className="org.apache.catalina.session.FileStore"
directory="/tmp/tc_sessions/"/>
</Manager>
</Context>
RE: Question on Contexts and resource pathing
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jeffrey Janner [mailto:Jeffrey.Janner@PolyDyne.com]
> Subject: RE: Question on Contexts and resource pathing
> > Remember that relative links are based on the web page the links are
> > accessed from, not to the base of the webapp. You need to use a
> > leading slash to base them on the webapp.
> I think Chuck got his absolute vs. relative pathing confused a bit.
> A leading slash, "/default.css", is interpreted relative to the hostname
> portion of the URL.
Correct; thanks for the clarification.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Question on Contexts and resource pathing
Posted by Jeffrey Janner <Je...@PolyDyne.com>.
> -----Original Message-----
> From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
> Sent: Tuesday, October 02, 2012 3:18 PM
> To: Tomcat Users List
> Subject: RE: Question on Contexts and resource pathing
>
> > From: Josh Gooding [mailto:josh.gooding@gmail.com]
> > Subject: Question on Contexts and resource pathing
>
> > when the application is zipped up and deployed out under
> > $CATALINA_HOME/webapps/ROOT
>
> For clarification, do you mean deployed _as_ ROOT, or _under_ ROOT?
> Webapps cannot be nested, so no webapp should be deployed _under_
> another.
>
> > I should be able to build the war to any name I want and still have
> > all of the links work, even if they are referenced like:
>
> > <link rel="stylesheet" type="text/css" href="/default.css" /> NOT ~>
> > <link rel="stylesheet" type="text/css"
> > href="${pageContext.request.getContext}/default.css" /> or
> > ../default.css
>
> Remember that relative links are based on the web page the links are
> accessed from, not to the base of the webapp. You need to use a
> leading slash to base them on the webapp.
>
> - Chuck
>
I think Chuck got his absolute vs. relative pathing confused a bit.
A leading slash, "/default.css", is interpreted relative to the hostname portion of the URL. That is, it gets expanded by the client as http://hostname.com/default.css. If you leave off the leading slash, "default.css" or "styles/default.css" then it's relative to the parent URL of the page, i.e. http://hostname.com/pageurl/default.css or http://hostname.com/pageurl/styles/default.css.
This is all done at the client end, before your server ever sees the request. Therefore, if you want the references relative to whatever you name the war file, and the name is not ROOT, you are going to have to include the reference to the context name in your href values.
Jeff
p.s. And, as well all know, absolute pathing starts at the "http://".
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Question on Contexts and resource pathing
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Josh Gooding [mailto:josh.gooding@gmail.com]
> Subject: Question on Contexts and resource pathing
> when the application is zipped up and deployed out under
> $CATALINA_HOME/webapps/ROOT
For clarification, do you mean deployed _as_ ROOT, or _under_ ROOT? Webapps cannot be nested, so no webapp should be deployed _under_ another.
> I should be able to build the war to any name I want and still have all of
> the links work, even if they are referenced like:
> <link rel="stylesheet" type="text/css" href="/default.css" /> NOT ~> <link
> rel="stylesheet" type="text/css"
> href="${pageContext.request.getContext}/default.css" /> or ../default.css
Remember that relative links are based on the web page the links are accessed from, not to the base of the webapp. You need to use a leading slash to base them on the webapp.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org