Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

not printed

Thread view: 
subi - 27 Dec 2005 06:23 GMT
Hi,

I am using property file to get a rate revision date. When I first use
the
getServletConfig().getServletContext().getRealPath("ratecheck.properties"),
i got the non-static method ServletConfig() can not be used in static
context. So I created one more method getPath() and used a member
method got it solved.

But I am still not able to get the RATEREVISION printed (im printing
the RATEREVISION below after some lines of other codings). It displays
nothing even an exception. I have both the the servlet and properties
file in same folder.

Please let me have a solution.

class test extends HttpServlet
{
    String getPath()
    {
        String
propFile=getServletConfig().getServletContext().getRealPath("ratecheck.properties");
        return propFile;
    }

    static String rateFinder()
    {
        String rate="";

        try
        {
            Properties prop= new Properties();
            String propFile=new test().getPath();

            File file = new File("ratecheck.properties");
            prop.load(new FileInputStream(propFile));

            rate=prop.getProperty("rate-revision");

        }
        catch (Exception e)
        {
            rate=e.getMessage();
        }
        return rate;
    }

    /*
    ...some codings..

    ..*/
    public final static String RATEREVISION = rateFinder();
}

Thank you,
Subi
zero - 27 Dec 2005 18:43 GMT
> Hi,
>
[quoted text clipped - 11 lines]
>
> Please let me have a solution.

<code snipped>

The following is a (non-servlet) test I wrote based on your code:

public class TestStatic
{
  public static final String STR = getStr();

  String getPath()
  {
     return "test";
  }

  static String getStr()
  {
     return new TestStatic().getPath();
  }

  public static void main(String args[])
  {
     System.out.println(STR);
  }
}

This works fine.  So, the problem probably is not with the code you
showed.  RATEREVISION should indeed be assigned correctly (although I
question the decision of creating an instance of a class to assign a
static final member variable).

I'm guessing the problem is in the code that prints this variable.  Or,
possibly it's printing correctly but not to the stream you're expecting.  
Are you printing to HttpServletResponse:getWriter()?

Signature

Beware the False Authority Syndrome

subi - 28 Dec 2005 05:26 GMT
Yes I am using HttpServletResponse. But I have to check as you said it
could be printing in different stream. Let me check it..

Thank you for your kind reply.

Thanks,
Subi
Raymond DeCampo - 01 Jan 2006 01:46 GMT
> Hi,
>
[quoted text clipped - 49 lines]
>     public final static String RATEREVISION = rateFinder();
> }

You can't just instantiate your servlet class and expect that
getServletConfig() will work correctly.  Why is rateFinder() static?

HTH,
Ray

Signature

XML is the programmer's duct tape.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.