
Hi i new to java i stuck here please help me... my problem is "I wrote a class to write the .properties file it is working fine when i run through normal application.But the problem is when i am using this in jsp means i have create object to this class and used it in my jsp but Iam unble to modify/write the .properties file and Iam not getting any errors".
what is the problem please explain and give if any solution to implement/write .properties file from jsp.
Regards, Venkatesh Gurram.

Hi Friend,
Try the following code:
1)properties.jsp:
<form method="post" action="create.jsp"> <table> <tr><td>Enter File Name:</td><td><input type="text" name="f">.properties</td></tr> <tr><td>Enter Key:</td><td><input type="text" name="key"></td></tr> <tr><td>Enter Value:</td><td><input type="text" name="value"></td></tr> <tr><td></td><td><input type="submit" value="Submit"></td></tr> </table> </form>
2)create.jsp:
<%@page import="java.io.*,java.util.*"%>
<%
String str = request.getParameter("f");
System.out.println(str);
if(!str.equals(null)){
try{
Properties p = new Properties();
File file=new File("C:/"+str+".properties");
p.store(new FileOutputStream(file),null);
String key = request.getParameter("key");
String val = request.getParameter("value");
p.setProperty(key, val);
p.store(new FileOutputStream(file),null);
System.out.println("Operation completly successfuly!");
}
catch(IOException e){
System.out.println(e.getMessage());
}
}
%>
Thanks

Below is a simple code package com;
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties;
public class PropertiesFile { static Properties prop;
public PropertiesFile() throws IOException {
prop = new Properties();
FileInputStream filestream = null;
try {
filestream = new FileInputStream("E://Selenium//workspace//Sample Test//src//com//sample1.properties");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
prop.load(filestream);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
PropertiesFile sp= new PropertiesFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String name= prop.getProperty("name");
System.out.println(name);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.