not printed

S

subi

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
 
Z

zero

Hi,

I am using property file to get a rate revision date. When I first use
the
getServletConfig().getServletContext().getRealPath("ratecheck.propertie
s"), 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.

<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()?
 
S

subi

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
 
R

Raymond DeCampo

subi said:
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();
}

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

HTH,
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top