Solved

Set a session variable from a properties file

Posted on 2006-11-29
6
554 Views
Last Modified: 2010-04-01

Hi all,

I it possible to set a session variable from some kind of properties file?

Ive been trying this:

session.setAttribute
( "amt, <bean:messagekey="sub.amt" /> );

But I get this error:

Missing term. session.setAttribute( "amt, <bean:messagekey="sub.amt" /> );

Thanks for any help
                                                                    ^
0
Comment
Question by:SuAeE
  • 3
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
bloodredsun earned 175 total points
ID: 18035805
Yes it is but not like that. You can't mix custom tags with scriptlet java code. You need to do it all in the scriptlet code.

<%
    // Read properties file.
    Properties properties = new Properties();
    try {
        properties.load(new FileInputStream("filename.properties"));//make sure the name of the file is correct
    } catch (IOException e) {
       //deal with the exception
    }
    //add the value to the session object
    session.setAttribute( "amt", properties.getProperty("sub.amt") );

%>
0
 

Author Comment

by:SuAeE
ID: 18035819

ah I see, ill try that, thanks
0
 

Author Comment

by:SuAeE
ID: 18037128

Im having trouble accessing the file

Im using:
  properties.load(new FileInputStream(request.getContextPath()+"//config//myProp.properties");

But im getting the error: "Cannot find the file specified"

I'll increase the points, thanks
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 27

Expert Comment

by:rrz
ID: 18037319
you can try using  
properties.load(new FileInputStream(request.getContextPath()+"/config/myProp.properties");
or
properties.load(getClass().getResourceAsStream(request.getContextPath()+"/config/myProp.properties"));
0
 
LVL 27

Assisted Solution

by:rrz
rrz earned 100 total points
ID: 18038446
Sorry, that last one needs to find it on the classpath( in the classes folder for example).  
properties.load(getClass().getResourceAsStream("/myProp.properties"));
0
 

Author Comment

by:SuAeE
ID: 18038709

thanks, ;)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
reflections, dynamic class loading 3 75
iterator example remove 8 75
lessBy10  challenge 15 95
How can I   ajax html table  rows? 20 78
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Smart phones, smart watches, Bluetooth-connected devices—the IoT is all around us. In this article, we take a look at the security implications of our highly connected world.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question