Solved

Set a session variable from a properties file

Posted on 2006-11-29
6
547 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now