venkatesh
How to write .properties file from jsp
2 Answer(s)      4 years and 9 months ago
Posted in : JSP-Servlet

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.

Advertisement
View Answers

November 24, 2010 at 1:20 PM


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



March 26, 2013 at 11:46 AM


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);
}

}










Related Tutorials/Questions & Answers:
How to write .properties file from jsp
How to write .properties file from jsp  Hi i new to java i stuck here... to implement/write .properties file from jsp. Regards, Venkatesh Gurram... it in my jsp but Iam unble to modify/write the .properties file and Iam not getting
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads the data from this .properties file and display it in table format. Ex:by using
Advertisements
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
Java Write to properties file
Java Write to properties file In this section, you will learn how to write data to properties file.  The properties file is basically used to store.... Here we are going to create a .properties file and write data
How to write properties file in java
Write properties file in java In this example we will discuss how to write property file in java. In this example We have write data to properties file. The properties file has fundamentally used to store the data configuration data
how to fetch values from .properties to a html file
how to fetch values from .properties to a html file  I have a .properties file with some key value pairs in it. I need to fetch the values from this .properties file into a html file.Please let me know how to do
how to write file from FileInputStream
how to write file from FileInputStream  Hi, How to Write a file.... Thanks,   Hi, For Write to file from FileInputStream in java you may use... this website Write to file from FileInputStream in java
how to write to file from string in Java
how to write to file from string in Java  Hi, Please any one help me for how to write to file from string in Java. I am beginner in Java programming. Thanks,   Hi, Are you eager to learn how to write to file from
How to write file from inputstream in java
How to write file from inputstream in java  Hi, how to write file from inputstream in java program. Plz suggest an example or suggested link... link to your query "How to Write to inputStream in Java". This is good
Loading properties from a XML file
Loading properties from a XML file       This Example shows you how to Load properties from a XML... parsers. Some of the methods used for loading properties from a XML file
write to file from servlet - JSP-Servlet
write to file from servlet  Hi, I have a jsp file where I input... right data on the web site. I am also trying to write this data to file... JSP Page //<
How to read properties file in java
How to read properties file in java Description of Example:- In this example... to a stream or load from a stream using the properties file. This properties... with the assigned key in the properties data file. How we will create .properties
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
Write Keys and Values to the Properties file in Java
Write Keys and Values to the Properties file in Java... how to write keys and values in the properties files through the Java program... to write or store the keys and values in properties file list. The OutputStream used
Java Read username, password and port from properties file
Java Read username, password and port from properties file In this section... the properties file and display the data from the database. Now to load the data from... to a stream or loaded from a stream using the properties file
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
Java Write To File From FileInputStream
Java Write To File From FileInputStream In this tutorial you will learn how to write to file from FileInputStream. Write to file from FileInputStream in java... input bytes from a file or can say it reads the streams of bytes. And to write
How to Write to file in Java?
How to Write to file in Java?  How to Write to file in Java Program... the Examples of How to write to File in Java Program: WriteToFileExample.java import... how to write in a file."); br.close(); } catch (Exception e) { System.err.println
use properties file to connect to the database in jsp..
use properties file to connect to the database in jsp..  How to use properties file to connect jsp code with database ..........   Here is a jsp code that connects to database using properties file. <%@page import
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... bufferedWriter object to write in the file. For more details and examples related to How to write in File of Java Program
Java Write To File From String
Java Write To File From String In this tutorial you will learn how to write to file from string. Write to file from string using java at first we will have... you how to write a file from string"; File file = null
How to read properties file in Java?
Example program of reading a properties file and then printing the data... to value. The java.util.Properties class is used to read the properties file. The properties files are simple text file which is saved as .properties
Java read properties file
Java read properties file In this section, you will learn how to read properties file. Description of code: There are different tools to access different files. Now to load the data from the properties file, we have used Properties
How to Write to a File in Java
In this Java tutorial, we will demonstrate how to write to a file in Java... will be able to use OutputStreamWriter on a FileOutputStream classes to write data to a file from Java program. To write the Java Write To File we will use two
Reading duplicate keys from .properties file - Development process
Reading duplicate keys from .properties file  Hi, I am reading a .properties file using a basic java program.Though the .properties file will not allow duplicate keys, but still I want to develope a program to identify
Problem to print from my properties file - Java Server Faces Questions
Problem to print from my properties file  Hi, I am a new user of this site. It is very interesting. So this is my problem: I have a jsp file where i try to print some messages from my properties file but when i execute
How to use an object properties in jsp page
How to use an object properties in jsp page  I have a arraylist of objects 'User' populated using struts 2 action class while loading that jsp page. In that JSP I have included another jsp using following tag: Here instead
Properties file in Java
to read key and it's regarding values from the properties file.   ..., you will learn how to write keys and values in the properties files through... Properties file in Java      
How to write into CSV file in Java
How to write into CSV file in Java  How to write into CSV file... passed the file name to write into a stream characters. Then we use the FileWriter Object to PrintWriter instance. How to create File to CSV in Java
How to write file by line in Java
How to write file by line in Java  How to write file by line in Java   Hi, For Write to a file by line using java programming language we... in a new line. How to use Write To File By Line in Java programs
how to write to file at the end of the line
how to write to file at the end of the line  Hi, Where do i learn how to write to file at the end of the line using Java program. Plz suggest... will help you for "How to write the file at the end of line using Java language