aspose file tools*
The moose likes Struts and the fly likes Changing <context-root> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Changing <context-root>" Watch "Changing <context-root>" New topic
Author

Changing <context-root>

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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

Joined: Oct 29, 2001
Posts: 8964
    
    9

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)


[How To Ask Questions On JavaRanch]
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
So would changing them to relative paths solve the issue?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

Yes (if that is the problem)
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

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


I love this place!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

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

Joined: Mar 04, 2009
Posts: 477
I just went through the code, looks like the images and other stuff are picked up using some CMS.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing <context-root>