> > I'm trying to load a java properties file and then read from that file.
> > But each time I try this it returns the value of Null.
[quoted text clipped - 32 lines]
> p.load( in );
> out.println( p.getProperty("servername") );
Please refrain from top-posting. It makes discussions hard
to understand.
> > > I'm trying to load a java properties file and then read from that file.
> > > But each time I try this it returns the value of Null.
> > >
> > > Any Ideas?
...
> > There are a number of ways to do this, but the following works for me on
> > OC4J stand-alone:
> >
> > URL
> > myURL=application.getResource("/WEB-INF/Administration.properties");
> Gives me an error of:
> Syntax error, insert "AssignmentOperator Expression" to complete
> Expression
> this is for teh variable URL.
URL is a class, myURL is a variable.
You may have missed the '='. If not, please be more clear.
> I've got it to work in a java core file but cant figure out how to do
> this in jsp.
That is always a good strategy, to do it in 'core Java'
(where possible) before putting it into something like
an applet or web-service, where it is more hassle to
deploy, and harder to debug.
Andrew T.
Ed - 05 Sep 2006 14:56 GMT
Andrew Thompson skrev:
> Andrew T.
Andrew, how's the head today?
.ed
--
www.EdmundKirwan.com - Home of The Fractal Class Composition.
Download Fractality, free Java code analyzer:
www.EdmundKirwan.com/servlet/fractal/frac-page130.html
RigasMinho - 05 Sep 2006 15:42 GMT
Okay - is this what you're telling me to write?
public class URL
{
myURL=application.getResource("/WEB-INF/Administration.properties");
InputStream in = myURL.openStream();
Properties p = new Properties();
p.load( in );
out.println( p.getProperty("servername") );
}
even that gives me errors:
- Syntax error on token "myURL", VariableDeclaratorId expected after
this token
- Syntax error on token(s), misplaced construct(s)
I guess i'm not understanding this too well.
I wrote my own java code that loads the properties but when i copy it
over to a jsp file it just doesnt work.
> Andrew Thompson skrev:
>
[quoted text clipped - 9 lines]
> Download Fractality, free Java code analyzer:
> www.EdmundKirwan.com/servlet/fractal/frac-page130.html
RigasMinho - 05 Sep 2006 15:43 GMT
Okay - is this what you're telling me to write?
public class URL
{
myURL=application.getResource("/WEB-INF/Administration.properties");
InputStream in = myURL.openStream();
Properties p = new Properties();
p.load( in );
out.println( p.getProperty("servername") );
}
even that gives me errors:
- Syntax error on token "myURL", VariableDeclaratorId expected after
this token
- Syntax error on token(s), misplaced construct(s)
I guess i'm not understanding this too well.
I wrote my own java code that loads the properties but when i copy it
over to a jsp file it just doesnt work.
> Andrew Thompson skrev:
>
[quoted text clipped - 9 lines]
> Download Fractality, free Java code analyzer:
> www.EdmundKirwan.com/servlet/fractal/frac-page130.html
Tim B - 05 Sep 2006 16:21 GMT
> Okay - is this what you're telling me to write?
> public class URL
[quoted text clipped - 6 lines]
> out.println( p.getProperty("servername") );
> }
No. The first line wrapped just after "URL", unfortunately
what you want is:
<%
URL myURL=application.getResource("/WEB-INF/myfile.properties");
InputStream in = myURL.openStream();
Properties p = new Properties();
p.load( in );
out.println( p.getProperty("servername") );
%>
and you'll need an import in the jsp - java.net.URL, I think.
Andrew Thompson - 05 Sep 2006 16:20 GMT
> Andrew Thompson skrev:
...
> > Andrew T.
>
> Andrew, how's the head today?
Not great. But I feel a lot better, than I deserve to. ;-)
Andrew T.
RigasMinho - 05 Sep 2006 16:43 GMT
Holy - crud it works.
Thanks - its weird the below code is the core java i wrote which works.
But somehow doesnt work in JSP. Gotta learn JSP better.
Here's a question - the code you wrote for the JSP properties loader -
the properties file would be stored in the project workspace right?
And not under the tomcat workspace deployed place right?
import java.util.Properties;
import java.io.*;
import java.*;
class Prop{
public static void main(String args[])
{
String strServername;
String myURL;
String osname;
Properties prop = System.getProperties();
osname = prop.getProperty("os.name");
if (osname.equals("Windows XP"))
{
try
{
Properties defaultProps = new Properties();
FileInputStream in = new
FileInputStream("PasswordAdministration.properties");
defaultProps.load(in);
in.close();
strServername = defaultProps.getProperty("portnumber");
System.out.println(strServername);
}
catch(IOException e)
{
String g;
g="error";
}
}
}
}
> > Andrew Thompson skrev:
> ...
[quoted text clipped - 5 lines]
>
> Andrew T.