aspose file tools*
The moose likes Servlets and the fly likes ContextRoot Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ContextRoot Problem" Watch "ContextRoot Problem" New topic
Author

ContextRoot Problem

Chris Cornelius
Ranch Hand

Joined: Aug 02, 2005
Posts: 48
Hello All,

I sometimes have a problem with the ContextRoot value in a session. For some unknown reason, every once in a while the ContextRoot in the session is deleted/wiped out. In one of my servlets, I am sending an image file from a BLOB in an oracle database to an applet in a jsp to be displayed. The proble m is that if a record does not have a corresponding image, the servlet sends a n image saying something like "No Image Available". This works most of the time, but when it fails I get a null pointer exception. Here is the method where the problem is occurring:



I have written and tested this in a Windows 2000 Environment, before it is deployed to a Unix based Web Server so I don't think hard coding the file directory will work.

Thanks in advance,

Chris Cornelius
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61419
    
  67

First things first. What is ContextRoot and how does get into the session in the first place? Is its disappearance merely an artifact of session expiry?

If ContextRoot is indeed the "context root", why are you getting it from a session variable rather than the API call on the request?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Chris Cornelius
Ranch Hand

Joined: Aug 02, 2005
Posts: 48
We were using the ContextRoot from the session to give the
directory for the no image file. The directory we stored it
in was the images folder of webroot. I have tried the contextPath
from the request and it does not give the correct path, unless
I have missed something, which wouldn't be the first time.

Thanks,

Chris
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61419
    
  67

We were using the ContextRoot from the session to give the
directory for the no image file.


Poorly named then, would you not say?

And why in the session? Is this path user-specific? If not, placing it in app context would eliminate any session timeout issues.

If the value is user-specific, and therefore needs to be in the session, then you'll need to handle your session transitions better.
Chris Cornelius
Ranch Hand

Joined: Aug 02, 2005
Posts: 48
Thanks for the tip. There was no reason to have the directory path
in the session, and I put the image file in the classes directory
inside of web-inf. And changed the code in the servlet to:



So far so good.

Thanks again,

Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ContextRoot Problem