Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder what that error is?
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Meet Gaurav
Can you post some part of the your code so that we can find reasons for error.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes deployed as a ear file that contains the war file.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shruthi Sam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also

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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic