Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set a session variable from a properties file

Posted on 2006-11-29
6
Medium Priority
?
560 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 700 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 28

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 28

Assisted Solution

by:rrz
rrz earned 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this article, the configuration steps in Zabbix to monitor devices via SNMP will be discussed with some real examples on Cisco Router/Switch, Catalyst Switch, NAS Synology device.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

926 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