Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > not printed

Reply
Thread Tools

not printed

 
 
subi
Guest
Posts: n/a
 
      12-27-2005
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().ge tRealPath("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

 
Reply With Quote
 
 
 
 
zero
Guest
Posts: n/a
 
      12-27-2005
"subi" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

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

--
Beware the False Authority Syndrome
 
Reply With Quote
 
 
 
 
subi
Guest
Posts: n/a
 
      12-28-2005
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

 
Reply With Quote
 
Raymond DeCampo
Guest
Posts: n/a
 
      01-01-2006
subi wrote:
> 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().ge tRealPath("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

--
XML is the programmer's duct tape.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File read from stdin and printed to temp file are not identicial? Jean Luc Truchtersheim Python 5 09-17-2010 12:35 AM
Not all data is printed from a datagrid lds ASP .Net 1 06-03-2009 04:55 PM
Why did the text added on photos not be printed out? Dong Digital Photography 3 11-21-2007 10:00 AM
How to verify that a printed web page has not been altered leeana1@gmail.com HTML 8 08-07-2006 07:01 AM
Data will not be printed on the browser completely Karuna Javascript 0 09-27-2004 01:19 PM



Advertisments