File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContext" Watch "ServletContext" New topic
Author

ServletContext

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Hi

I have a servlet and this is looking up for a file for that I used this.getServletContext().getRealPath("/");

In OC4J its working fine. But in Weblogic it's throwing some error please assist me.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I wonder what that error is?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
In the catch block, ex.getMessage() is returning null. Am having a log only(from different location). So unable to print the stack trace.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So, does:

not return anything? That seems very odd. Can you post your code?


Am having a log only(from different location). So unable to print the stack trace.

Not sure what you mean by this, but I'm struggling to think of a reason why you would be prevented from printing the stack trace. Can you explain more?
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 784

@Meet Gaurav
Can you post some part of the your code so that we can find reasons for error.


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492

Am sure its failing in "String rootp = getServletConfig().getServletContext().getRealPath("/");."

Currently it's from procuduction env. So unable to change the code now.
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492

Am sure its failing in "String rootp = getServletConfig().getServletContext().getRealPath("/");."

Currently it's from procuduction env. So unable to change the code now.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Prodution code using System.out.printlns?! Well, if nothing else this problems is maybe highlighting why this is a very bad idea.

OK, since all anyone can do is guess I'll guess you have deployed your application as a war file rather than a directory?
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Yes deployed as a ear file that contains the war file.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

In which case that code is just not going to work. You can't reliably call getRealPath for a path inside a war file (as the JavaDocs for getRealPath() say). You will need to change the code to either get the location of the path from somewhere else, or load whethever you need from the war file as a resource via the classloader.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

A title such as "ServletContext" is not helpful. What would happen if all posts had such a title?

Please go back and change your post to add a more meaningful subject by clicking the button on your post.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shruthi Sam
Ranch Hand

Joined: Jul 09, 2008
Posts: 73
Hi,
Inside the catch you have written System.out.printl (..) is that a spelling mistake when you typed?



I don't think it will get compiled if you use the same.
Shruthi Sam
Ranch Hand

Joined: Jul 09, 2008
Posts: 73
Also

ex.getMessage() is a method. I don't find any open brace and close brace(). please check that.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContext
 
Similar Threads
The x900 effect ?
Cant use object from another class
Posting to bump up my count...
Text box value is not being completely filled with request attribute
WA #1.....word association