How to write .properties file from jsp

Ads
 

How to write .properties file from jsp

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.

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

}

Ads









Related Tutorials/Questions & Answers:
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
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
Advertisements
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 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
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 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
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
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file . look at the line with code-> Statement st=con.createStatement(); in the below example. the error is "cannot convert from java.sql.Statement
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 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
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
how read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
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... of: "How to read properties file in Java?" How we will create
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
Version of com.internetitem>write-properties-file-maven-plugin dependency
List of Version of com.internetitem>write-properties-file-maven-plugin dependency
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 backup a selected file from the dropDown Menu in JSP?
How to backup a selected file from the dropDown Menu in JSP?  I am trying to create a dropdown menu list for some type of files contained ina... file into the backup directory. I need the jsp code that can generate
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
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
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload  Dear Sir, My issue is: How display a image on servlet from file upload I receive your answer today...: Unknown File Type From: localhost button - Find, Save, Cancel after clicking
I need jsp code for how to write text field value into property file.
I need jsp code for how to write text field value into property file.  Hi , I need to set the text field value into property file using jsp code... ,then the value should be stored in the property file like Username = Valar
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
How to write to file using FileOutputStream
How to write to file using FileOutputStream  Hi friends, Please help me in java program. How to write to file using FileOutputStream? thanks,   Hi, To write a file using FileOutputStream, we have to use
How to Write To File BufferedWriter in Java
How to Write To File BufferedWriter in Java  how to write to file... in Java.io package i.e. FileWriter and BufferedWriter file. In this section we... to write texts. In this classwe stores the character in a buffer to write
How to write to xml file in Java?
How to write to xml file in Java?  Hi Friends, Can anyone help me how to write in xml file in Java programming. Please fill free to give example or reference website for getting example.   Hi, To write in xml file
how to write append file in Java
how to write append file in Java  How to write append file in Java... existing file should be retained when you are trying to write new contents...("appenToFile.txt", true); For More Details visit this link: How to Append file

Ads