Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing <context-root>

 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I recently took over an application in my office. The application is using Struts 2.0 framework, tiles, JAVA and JSP's mostly. We are using WebLogic 10.0 as the application server.

Recently there was a requirement in which required to change the context-root. But as soon as I changed it and re-deployed the application the whole pages have gone astray. The images and JSP's do no get rendered properly. I know that i have to make changes somewhere. But don't exactly know where! Could you guys let me know on the impact that it would have and how to solve this. I have to keep the new context-root and make the application working again!

Previous application.xml

New application.xml
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you've specified paths using an absolute url (e.g. /context/images/animage.jpg) as opposed to a relative url (e.g. images/animage.jpg)
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So would changing them to relative paths solve the issue?
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes (if that is the problem)
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somnath Mallick wrote:So would changing them to relative paths solve the issue?

Not entirely as you would still need to prepend the correct context path instead. You also want to do it in a way that if it changes again you don't have to repeat this process.
If you use the <c:url /> tag then it will add this for you.

see: JSTL docs

Sean
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean Clark wrote:
Not entirely as you would still need to prepend the correct context path instead.



If you have a resource, say:
<img src="images/someimage.jpg">
and your app is deployed to, say, /x/y/z, the URL of the image above is at /x/y/z/images/someimage.jpg
If you change the context root to, say /a/b/c, the URL of the image above is /a/b/c/images/someimage.jpg.
No prepending necessary.>
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just went through the code, looks like the images and other stuff are picked up using some CMS.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Ess wrote:
Sean Clark wrote:
Not entirely as you would still need to prepend the correct context path instead.



If you have a resource, say:
<img src="images/someimage.jpg">
and your app is deployed to, say, /x/y/z, the URL of the image above is at /x/y/z/images/someimage.jpg
If you change the context root to, say /a/b/c, the URL of the image above is /a/b/c/images/someimage.jpg.
No prepending necessary.>


You are making the assumption the the .jsp file is at the root of the web application, which in in my experience is almost never the case. If you had a directory listing like this:

Which is something more like I would have your image tag on the myJsp.jsp page would need to be:
<img src="../../images/someimage.jpg">

then what happens if you move your JSP into your home folder, all your images stop working and you need to change it to:
<img src="../../../images/someimage.jpg">

better to use something like this which will work no matter where the jsp is located:
<img src="<c:url value='/images/someimage.jpg'/>">

This is still a relative URL, however it is relative from the root of the context.

Anyway sorry this has gone slightly off topic.

Sean
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic