Results 1 to 7 of 7

Thread: ExtJS access to a properties file content loaded via index.jsp page

  1. #1

    Default ExtJS access to a properties file content loaded via index.jsp page

    Hello, I need to externalize some of my webapp services (paths to services used in my application). I have a properties file ( located on the same server as tomcat that's running my ExtJS webapp ( /privatefolder/ ) for instance. I want to be able from JavaScript (or ExtJS framework) to access those properties that are loaded into memory... how can I do this?

    I use my index.jsp page to load this file as such (here is a snippet from the index.jsp):

    <script type="text/javascript" src="lib/extjs/adapter/ext/ext-base-debug.js"></script>
    <script type="text/javascript" src="lib/extjs/ext-all-debug.js"></script>
    <%@page import="" %>
    <%@page import="java.util.Properties" %>
    Properties properties = new Properties();
    properties.load(new FileInputStream("/privatefolder/"));
    out.println( properties.getProperty("profileservice") );
    // The properties file is loading fine, I see the output displayed for the property "profileservice", but I want to be able to read those properties elsewhere in my ExtJS code... is this possible?

    I've searched the net looking for clues, but so far nothing concrete.
    I've never done this before, but seems natural, any help would be greatly appreciated...

    OR perhaps I'm going about this all wrong , is there a better way to externalize a properties file outside my app (war file) for ExtJS applications?
    Last edited by cavalleydude; 8 Oct 2010 at 7:32 AM. Reason: add more details

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    The Netherlands


    Create a .jsp that outputs all properties as a JSON object that is assigned to a variable, e.g.
    Ext.ns('MyNamespace'); = {
      // dynamically filled from /privatefolder/
      profileservice: 'abc',
      otherproperty: 123
    Then, simply include this .jsp with a <script> tag.

  3. #3


    Okay, that sounds good. I'm trying to understand how to write this jsp file. How do I read the properties into the json object?

    My new jsp file will be myappservices.jsp
    <%@page import="" %> 
    <%@page import="java.util.Properties" %>  
    <% Properties properties = new Properties(); %>
    <% properties.load(new FileInputStream("/privatefolder/"));%> 
    // The question is, how do I get from properties into the json object values below?
      <json:property name="profileservice" value="${element.profileservice}" />
      <json:property name="demoservice" value="${element.demoservice}" />   
      <json:property name="authservice" value="${element.authservice}" />

  4. #4


    Hi Condor, I think I know how to do this... I was not thinking. I'll try it and post results shortly.

  5. #5


    Actually, do you have an example of how to do this? How do I get the namespace assigned, etc. It sounds like I'm going to write the output as a <script> </script> with the JSON object assigned to a var object. It would really help to see an example... if you have one.

  6. #6


    Okay, SOLVED... Condor thank you for the help. I found a slightly different way to do it.

    A file resides on the server named "" in a private folder (not in the web server) and contains the following:


    I created a new javascript file named "MYAPP.js"
    with contents

    MYAPP = {
     * Constants for MYAPP
    MYAPP.Constants = {
        devBaseServiceUri :'http://mydevserver/rest',
        testBaseServiceUri : 'http://mytestserver/rest',
        prodBaseServiceUri : 'http://myproductionserver/rest'
    Then inside the index.jsp it will load my java properties file, and set the values in the environment.
    A final script will read environment values into my JavaScript object variables.

    <script type="text/javascript" src="js/MYAPP.js"></script>
    <%@page import="" %>
    <%@page import="java.util.Properties" %>
    Properties properties = new Properties();
    properties.load(new FileInputStream("/privatefolder/"));
    System.setProperty("mydevservername", properties.getProperty("devBaseServiceUri") );
    System.setProperty("mytestservername", properties.getProperty("testBaseServiceUri") );
    System.setProperty("myprodservername", properties.getProperty("prodBaseServiceUri") );
    <script type="text/javascript">
        MYAPP.Constants.devBaseServiceUri = "<%= System.getProperty("mydevservername")%>";
        MYAPP.Constants.testBaseServiceUri = "<%= System.getProperty("mytestservername")%>";
        MYAPP.Constants.prodBaseServiceUri = "<%= System.getProperty("myprodservername")%>";
    Then inside the application anywhere, you can call MYAPP.Constants.devBaseServiceUri for the value read from the properties file.

    Anyhow,... thank you so much. You got me on the right track.

  7. #7

    Default How to read constants file using html file or using .js file only?

    Hi, I am using simple HTML file for my extJS project. How can I load/read a properties file or constants file using that HTML file or .js file?

    any kind of help will be appreciated.
    Thanks in advanced.

Similar Threads

  1. Help:extJS with JSP page
    By kunalkrishna in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 10 Aug 2011, 7:14 AM
  2. opening a jsp page in ExtJs window
    By himan in forum Ext: Q&A
    Replies: 2
    Last Post: 7 Jul 2010, 1:31 PM
  3. Executing extjs code in page loaded through extjs
    By smoothiegunner in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 8 Feb 2010, 5:27 PM
  4. How to load extjs datagrid in beteen a JSP page.
    By bhanuprakash_kavi in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 23 Aug 2009, 6:29 AM
  5. How to access Ext.Window context from an ajax loaded HTML file?
    By SkoalFyfan in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 31 Oct 2007, 8:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts