java - Changing Tomcat web application context -
i have web application, designed , worked under root context ("/"). css
, js
, links started /
(for example /css/style.css
). need move web application different context (let's /app1
). easy change server.xml
configuration file , bring web application in new context app1
using [context path=""]
item. web pages broken because links incorrect. point old root context /css/style.css
instead of new app1
context. there magic way fix problem without fixing each link prefixing "context" variable? used server - tomcat 5. application written java , uses jsp, struts2, spring , urlrewrite filter. more interesting hear real experience in fighting such problems theoretical debates. thank you.
p.s. not see how urlrewrite filter can me because work in app1
context. requests links /css/style.css
not passed it.
you should create urls via url re-writing, not session info can added url, if required, context path can added. should create urls absolutely paths top of application , let url-rewriting handle adding context-path front, appropriate.
<c:url value="/css/site.css"/>
that render /<context-path>/css/site.css
or /<context-path>/css/site.css;jsessionid=134345434543
jsp file if don't have cookies enabled. can use c:url tag render url variable , use variable multiple times throughout document. add var="x"
attribute tag , ${x}
render url doc. if aren't using jsp render output, you'll need find appropriate mechanism view layer, have one. if rendering url in java code, take @ source code c:url tag , you'll see how done.
the 1 awkwardness css files (and js files) aren't processed, urls in css , js files need relative paths or break whenever change context path. js uses relative paths since library maintainers don't know path going install library to. css backround images, on other hand, specified absolute urls, since same css file may included html files @ different levels of file hierarchy. there no easy fix aware of other create appropriate symlinks such relative url works or else serve problem css files via jsp urls can rewritten appropriate. i'm sure there filters or apache modules can run url replacement, you've still got manually update filter/module whenever deploy new context path.
Comments
Post a Comment