Solved

Set a session variable from a properties file

Posted on 2006-11-29
6
550 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
caughtSpeeding java challenge 16 136
How to Make JSP Pages Responsive ? details are below 3 736
How to Post an If Statement in JSP 3 54
mysql jsp example issue 32 32
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

17 Experts available now in Live!

Get 1:1 Help Now