Solved

Set a session variable from a properties file

Posted on 2006-11-29
6
555 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
Stuck in Bootstrap WysiHtml Editor 3 45
maven project in eclipse 11 62
own marker interface 1 61
if statement not resolving in my code 5 56
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The goal of this blog is to: > note what has impeded us from reaching effective life on-call > provide 3 steps to mastering life on-call > highlight what will be achieved with effective life on-call
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 …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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