File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ContextRoot Problem

 
Chris Cornelius
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Chris Cornelius
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic