-
8 Oct 2010 7:20 AM #1
ExtJS access to a properties file content loaded via index.jsp page
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 (my.properties) located on the same server as tomcat that's running my ExtJS webapp ( /privatefolder/my.properties ) 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):
// 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?Code:... <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="java.io.FileInputStream" %> <%@page import="java.util.Properties" %> <% Properties properties = new Properties(); properties.load(new FileInputStream("/privatefolder/my.properties")); out.println( properties.getProperty("profileservice") ); %> ...
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
-
8 Oct 2010 7:44 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Create a .jsp that outputs all properties as a JSON object that is assigned to a variable, e.g.
Then, simply include this .jsp with a <script> tag.Code:Ext.ns('MyNamespace'); MyNamespace.properties = { // dynamically filled from /privatefolder/my.properties profileservice: 'abc', otherproperty: 123 };
-
8 Oct 2010 8:07 AM #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
Code:<%@page import="java.io.FileInputStream" %> <%@page import="java.util.Properties" %> <% Properties properties = new Properties(); %> <% properties.load(new FileInputStream("/privatefolder/my.properties"));%> // The question is, how do I get from properties into the json object values below? <json:object> <json:property name="profileservice" value="${element.profileservice}" /> <json:property name="demoservice" value="${element.demoservice}" /> <json:property name="authservice" value="${element.authservice}" /> </json:object>
-
8 Oct 2010 8:18 AM #4
Hi Condor, I think I know how to do this... I was not thinking. I'll try it and post results shortly.
-
8 Oct 2010 8:45 AM #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.
-
8 Oct 2010 10:51 AM #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 "myfile.properties" in a private folder (not in the web server) and contains the following:
Code:devBaseServiceUri=http://adiffdevserver/rest testBaseServiceUri=http://adifftestserver/rest prodBaseServiceUri=http://adiffprodserver/rest
I created a new javascript file named "MYAPP.js"
with contents
Then inside the index.jsp it will load my java properties file, and set the values in the environment.Code:MYAPP = { } /** * Constants for MYAPP */ MYAPP.Constants = { devBaseServiceUri :'http://mydevserver/rest', testBaseServiceUri : 'http://mytestserver/rest', prodBaseServiceUri : 'http://myproductionserver/rest' }
A final script will read environment values into my JavaScript object variables.
Then inside the application anywhere, you can call MYAPP.Constants.devBaseServiceUri for the value read from the properties file.Code:<script type="text/javascript" src="js/MYAPP.js"></script> <%@page import="java.io.FileInputStream" %> <%@page import="java.util.Properties" %> <% Properties properties = new Properties(); properties.load(new FileInputStream("/privatefolder/myfile.properties")); 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")%>"; </script>
Anyhow,... thank you so much. You got me on the right track.
-
10 Sep 2011 11:44 PM #7
How to read constants file using html file or using .js file only?
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
-
Help:extJS with JSP page
By kunalkrishna in forum Ext 2.x: Help & DiscussionReplies: 6Last Post: 10 Aug 2011, 7:14 AM -
opening a jsp page in ExtJs window
By himan in forum Ext: Q&AReplies: 2Last Post: 7 Jul 2010, 1:31 PM -
Executing extjs code in page loaded through extjs
By smoothiegunner in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 8 Feb 2010, 5:27 PM -
How to load extjs datagrid in beteen a JSP page.
By bhanuprakash_kavi in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 23 Aug 2009, 6:29 AM -
How to access Ext.Window context from an ajax loaded HTML file?
By SkoalFyfan in forum Ext 2.x: Help & DiscussionReplies: 5Last Post: 31 Oct 2007, 8:44 AM


Reply With Quote