Overwritting the values in the property files
Hi All
I am new to reading property file in java. I am able to read the property files but it is overwritting my key/value pair.
The main thing when I am comparing the adminname which is present in the property file with the username which I am getting in the servlet request.
Its only comparing the last key/value pair ie.., adminname=ghj.
Can anyone help me regarding this...please..
i need to check whether userName(Servlet request) matches with any one of the values(abc,cde ,fgh,ghj) present in the property file.
But in my case it is only comparing the last value only.
for Eg:
admin.properties
one key and number of values. Can I do this?
adminname=abc
adminname=cde
adminname=fgh
adminname=ghj
// if they want to add or remove the admin people they are going to do it from property file which is the text file.
import java.io.*;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.*;
public class ExampleFilter implements Filter {
private FilterConfig filterConfig=null;
public void init(FilterConfig config) throws ServletException {
this.filterConfig = config;
public void destroy() {
filterConfig = null;
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
RequestDispatcher rd = null;
String userInfo = "";
String userName="";
if (request instanceof HttpServletRequest) {
userInfo = ((HttpServletRequest) request).getUserPrincipal()
.getName();
String[] pieces = userInfo.split("\\\\"); // Firefox sends DOMAIN\USERNAME as UserPrincipal
userName = pieces[pieces.length -1]; // getting the username for which I need to perform check
try
Properties propertiesFile = new Properties();
FileInputStream file =
new FileInputStream("C:\\webapp\\WebContent\\WEB-INF\\lib\\admin.properties");
if (file == null)
throw new NullPointerException("Properties file 'admin.properties' is missing in classpath.");
propertiesFile.load(file);
propertiesFile.list(System.out);
val=propertiesFile.getProperty(adminname);
//here watever the last key/value is present in the admin.properties, I am getting it.
//In the above property files i will get "ghj"
System.out.println("adminName In Property file:" +val);
if(userName.equals("val"))
// I NEED TO COMPARE THE USERNAME WITH THE adminname IN THE PROERTY FILE (admin.properties)
// IF userName=anyone value in the property files.......... I AM FORWARDING IT TO REGULAR PAGE
chain.doFilter(request, response); // if username is present in proeprty file, I need to navigate to normal pages.
else{
//IF adminname is not present i m forwarding to ERROR PAGE
rd = request.getRequestDispatcher("/admin/error.html");
rd.forward(request, response);
catch(Exception e)
e.printStackTrace();
}
Read the java.util.Properties API. You can't have multiple same keys. Use one key or a key with some suffix, e.g. adminname.1 and so on or so.
This has nothing to do with servlets. You've a problem with classes of java.util package, not of javax.servlet package. Use the 'New to Java' forum.
Similar Messages
-
How can i get the all values from the Property file to Hashtable?
how can i get the all values from the Property file to Hashtable?
ok,consider my property file name is pro.PROPERTIES
and it contain
8326=sun developer
4306=sun java developer
3943=java developer
how can i get the all keys & values from the pro.PROPERTIES to hashtable
plz help guys..............The Properties class is already a subclass of Hashtable. So if you have a Properties object, you already have a Hashtable. So all you need to do is the first part of that:Properties props = new Properties();
InputStream is = new FileInputStream("tivoli.properties");
props.load(is); -
How to configure the property file
Is this the correct way of configuring the property file in web.xml.
<servlet>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>com.test.prod.pds.Controller</servlet-class>
<init-param>
<param-name>LOGINID</param-name>
<param-value>C:\bea\user_projects\domains\mydomain\applications\TestWebApp\WEB-INF\classes\loginid.properties</param-value>
<description>Pds Group properties file</description>
</init-param>
</servlet>
IT is giving an error "javax.servlet.ServletException: loginid.properties (The system cannot find the file specified)"Hi,
Place that properties file in the application classpath Then it will work fine without any problems.
Go through the follwing links,In that you will get usefull information on this.
http://jtidy.sourceforge.net/multiproject/jtidyservlet/configuration.html
http://www.utdallas.edu/~baughman/velocity4.html
Regards
Anilkumar kari -
Hi All,
How to add the property file..ie(default.properties) to a webdynpro project.
I urgently require the solution. Kindly get it for me.
Regards
DKHi DK,
this is described in the second Web Dynpro Java Tutorial
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/b1a3e990-0201-0010-aeb2-a2ef5bc3da8e">creating an Extended Web Dynpro Application</a>
Regards, Bertram -
In Vista, Applet isn�t able to read the property files
I�m working on internationalization; the Applet which I�m using wasn�t able to read the property files properly in windows Vista machine. But if I create a jar which contains all the classes and property files, Applet works fine.
This problem is only in Vista machine ,In XP the JVM is smart enough to read plain .property files and its works well without creating the jar
Is that related to any security enhancemence of vista over XP?
Below is a link about The Java Security Model break on Windows Vista
http://bugs.sun.com/view_bug.do?bug_id=6548078
I tried a simple ResourceBundle.getBundle() in my Applet in different ways but nothing work fine for me. It isn�t an issue related to path, I guess because I tried several ways like.
ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle");
ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle",currentLocale);
ResourceBundle labels = ResourceBundle.getBundle("com.test.LabelsBundle");
ResourceBundle labels = ResourceBundle.getBundle("com.test.LabelsBundle",currentLocale);The exception got in java console is
CONFIG: [2008-05-13 15:54:57.909]:(com.satm.insite.InsiteApplet$2@1696e4c):InisiteApplet: Exception: java.util.MissingResourceException: Can't find bundle for base name LabelsBundle, locale en
java.util.MissingResourceException: Can't find bundle for base name LabelsBundle, locale en
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at com.satm.insite.InsiteApplet.displayValue(InsiteApplet.java:261)
at com.satm.insite.InsiteApplet.callme(InsiteApplet.java:296)
at com.satm.insite.InsiteApplet.initialize(InsiteApplet.java:327)
at com.satm.insite.InsiteApplet$2.run(InsiteApplet.java:235)
at com.satm.tools.languageTools.ThreadPool$ExceptionCatchingThread.run(ThreadPool.java:226)Is there any way to make it work in Windows Vista machine�? This could be a great help for me.
Thanks
RobertCrossposted:
http://forum.java.sun.com/thread.jspa?threadID=5295743&messageID=10250558#10250558
http://forum.java.sun.com/thread.jspa?threadID=5295742&messageID=10250556#10250556 -
How to overwrite the xml file by flash using Php
Hi
i am creating getting data from the xml file ... and i am
doing some Alteration in the xml file by flash after that flash
producing the xml file i finished upto this process...
nw i neeed to overwrite the xml file.... using Php.....
can any one give me some idea ... to solve this issue
~~SKFlash Player cannot write XML files at all. but using
php+flash we could do it . -
hi
is there any other possible way to overwrite the xml file
using the javascript ....
Thanks in Advance
~~
SKThanks Feldkircher for your reply, But in my Project we are
using javascript , so we can't migrate for Php.
so is it possible to overwrite the xml file by using
javascript . Bcoz after flash produced the xml file i am going to
pass as string to javascript through external Interface. from there
i need to overwrite the xml file by javascript
is it possible to find the solution by this way...
~~
Sk -
Very basic question... can photoshop overwrite the original file?
Very basic question... can Photoshop Elements 13 overwrite the original file?
You will need to check the Photoshop Elements for any particulars about that software.
For Photoshop, if I make changes and exit saving those changes, yes the original is overwritten.
Keep backups at all times and don't work off flash external drives. When people tell me their original 500 layer file got corrupted, and they didn't keep copies, I hate to tell them their weeks of work is down the bucket.
In Photoshop, we use Image > Duplicate to work on a copy if we don't want the original touched, or File > Save as... where we give the file a different name. We save image.psd as image1.psd and image.psd is closed. We then have a copy, "Image1" opened.
Gene -
How to overwrite the xml file...
Hi,
can any one help me how to overwrite the xml file.....
~~SkFlash Player cannot write XML files at all. but using
php+flash we could do it . -
Make the property file separate and remain just text file
when I go "data" menu - "connect to Web Service..." to generate classes for webservice client,
In the WSDL file the IP address is set.
if the ip address doesn't vary, that doesn't matter at all.
but I have to make client for general case which means the webservice server ip is not set, so I want make property file(text file) for IP address.
if I compile the files(*.as) they compiled and include the ip address in it so I can't see any property file in the deployed folder.
How can I make the property file separate and just change the ip address any time, any place.
I used
<mx:Metadata>
[ResourceBundle("flex_dmb")]
</mx:Metadata>
I don't know flex very well.
I just click and click...
Thanks.I use flex 4
-
Maven Plugin not accepting values from a property file.
Hi,
I want to create javadocs using maven.
It works fine when i provide all the absolute paths in the pom.
But when i try to provide paths by reading a property file then the maven-javadoc-plugin does not get the paths from this property file.
The property file is defined as mentioned in below format:
src_mvn_consult_framework_dir=/var/lib/hudson/jobs/CZ_NAB_CORE_MVN_CHECKOUT/workspace/middleware/projects/framework
src_mvn_consult_module_dir=/var/lib/hudson/jobs/CZ_NAB_CORE_MVN_CHECKOUT/workspace/middleware/projects/module
src_mvn_consult_appx_dir=/var/lib/hudson/jobs/CZ_NAB_CORE_MVN_CHECKOUT/workspace/middleware/projects/appx
src_mvn_consult_client_dir=/var/lib/hudson/jobs/CZ_NAB_CORE_MVN_CHECKOUT/workspace/middleware/projects/client
src_mvn_consult_app_webservice_dir=/var/lib/hudson/jobs/CZ_NAB_CORE_MVN_CHECKOUT/workspace/middleware/application/com.ofss.fc.cz.nab.webservices
src_mvn_consult_app_middleware_dir=/var/lib/hudson/jobs/CZ_NAB_CORE_MVN_CHECKOUT/workspace/middleware/application/com.ofss.fc.cz.nab.middleware
Calling this property file in the pom like:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>/var/build/consult/maven/cz_javadoc-config.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
Finally we are using keys defined in property file in pom like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<sourcepath>${src_mvn_consult_framework_dir};
${src_mvn_consult_module_dir};
${src_mvn_consult_appx_dir};
${src_mvn_consult_client_dir};
${src_mvn_consult_app_webservice_dir};
${src_mvn_consult_app_middleware_dir};
</sourcepath>
</configuration>
</plugin>
Please suggest how we can get the value of keys defined in the property file in POM
Thanks for your invaluable supportI've had to do something similar in one of my apps. In order to populate values in the THIS scope, you'll need to put a copy of the XML loading/processing logic in the pseudo-constructor (or encapsulate it in a separate CFM/CFC file and include it in both places). It's ugly, but that's the only way I'm aware of to access the THIS scope.
-Carl V. -
How to use an equal sign as a part of the value in a property file
say I have this line in a properties file:
args = -Xms512m -Xmx512m -XX:MaxPermSize=256m
obviously I can't use the (=) as is. What should I do to make it work?
I tried to use \= and \:, but it doesn't work as well.
thanks.A property file contains "key" lines or "key=value" lines the '=' character loses its special meaning after a key is read so you can use '=' characters in the 'value' part of a property.
kind regards,
Jos -
Removing the user define comments while trying to write to the property fil
Hi All,
While using new Properies().setPropety(). It is removing the user define comments from property file.
Could you please explain me why it is happening and how can I restrict it
Thanks & Regards
Edited by: Rakesh83 on Feb 20, 2008 4:33 AMRakesh83 wrote:
Could you please provde me sample code for this?
#! /usr/bin/groovy
xml = '''
<config>
<property name="foo" value="bar" comment="blah, blah, blah" />
<property name="baz" value="qux" comment="doodle doodle dee" />
</config>
def config = new XmlParser().parse(new StringReader(xml))
def property = config.property.find { it.'@name' =~ 'baz' }
assert 'doodle doodle dee' == property.@comment
property.@value = 'snorp'
assert 'doodle doodle dee' == property.@comment // comments preserved!
// write xml as needed~ -
Hi my name is Dustin,
I am new to labview and teststand... I am trying to right multiple arrays of data to a single xml file. I can do this with a cluster but I have to create a variable for each of those arrays (21 arrays) and I was hoping to use the same variable for each array. Meaning I obtain my array of data write it to an xml file then replace that array in that variable with a new array and then call up my VI that writes that array to an xml file and write it to the same xml file underneath the first array without overwriting it. Attached is my VI I created to write an array to an xml file. Again I am wondering if there is a way to write multiple arrays to a single xml file at different times without overwriting the previous xml file.
Thanks
Solved!
Go to Solution.
Attachments:
Write_to_XML_File.vi 11 KBHi dlovell,
Check the attached example. I think it may help you.
Regards,
Nitz
(Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved)
Attachments:
Write to XML.vi 17 KB -
How will read the property file on dynamically?
hi,
I developed 2 java files...in both the files i am reading the some content from .property file(Notes.properties)....
I created the jar file call Aix.jar using the following command.
jar -cvf Aix.jar *.class(without specifying the notes.properties file)...
then i executed the java file using the folowing command
java -cp Notes.jar;Aix.jar NotesToolTest
now i am getting following exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.util.MissingResourceException: Can't find bundle for base name Notes, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at NotesToolTest.<clinit>(NotesToolTest.java:28)
I got the problem why this happening...because notes.properties is not included in jar file...that's why the above exception is coming.
But my problem is can i run the java file that will take .prooperties file dynamically(if .property is available on the current directory)...
Thanks in advance,,,,
Regards,
Sankarbecause notes.properties is not included in jar file..Wrong. It is simply not available in the classpath.
The solution is either putting the properties file in the classpath of JVM used, or adding the system path to the propertiesfile to the classpath of the JAR.
Maybe you are looking for
-
Error at phase "Configure SLD" NW 7.0 Central instance step
Hi All I am installing NW 7.0 EHP1, on clustered Oracle10g, win2003. I have an error on AMSC step, configure SLD. here some logs java.exe.log ConfigMainExt state401 TYPE=A<BR>STATE=401<BR>INFO_SHORT=Error connecting to http://AAAPRD:50200/ctc/Config
-
To close popup page from parent page .
HI , I want to close the popup page when my parent page is redirected to login page when session gets invalidated. with out calling any onload or any kind of functions in popup jsp page. In my application when i open a popup page from the main page ,
-
We have recently moved office and our RPS 675's have ended up connected with an AC power cord with a 5A fuse. The unit itself is rated at 10-6A so I'm thinking the power cords have been mixed up and should have a higher rated cable (like 10Amp). Unfo
-
Where Are My Missing Master Images?
I keep my Aperture Library as a "managed" library rather than "referenced, so every master image is kept inside the Aperture Library icon. Today I decided to look inside my Aperture Library (by selecting Show Package Contents), and I can only find ma
-
How to divide sections of a book, lock in each chapter
I'd like to divide the chapters of a book into separate sections primarily to lock in each chapter's starting page. This is so alterations of a few lines in preceding chapters don't push the next the next chapter out of place by a few lines. Thank yo