Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners NOT ABLE TO MAKE A NEW FILE IN SERVLET
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


prateek gupta
NOT ABLE TO MAKE A NEW FILE IN SERVLET
1 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


What is the error in my code? It is not making a new file which contains the string values coming from a HTML page. Any help appreciated.

Code is-:

package myprogram;

import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.RequestDispatcher;

public class LoginPageServlet extends HttpServlet
{
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
    {
        res.setContentType("text/html");

        String fname=req.getParameter("p1");
        String lname=req.getParameter("p2");

        PrintWriter out=res.getWriter();

        out.println("HI from Login Page Servlet");
        out.println(fname);

        try{

        File file=new File("C://abc.xml");

        FileWriter fr=new FileWriter(file,true);

        BufferedWriter br=new BufferedWriter(fr);

        br.write("First Name" +fname + " Last name is " + lname);

        br.newLine();       

        out.println("File is created successfully");

        br.close();
        }

        catch(Exception e)
        {
            e.printStackTrace();

        }


    }


}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
make a file password protected
make a file password protected  I am trying to write Java code for creating a file of any type (either text,csv,or any other format). What I need is : The file generated should be zipped and password-protected. When I try to open
New to JSP..need help to make & run a JSP program.
New to JSP..need help to make & run a JSP program.  Hi, I have installed Tomcat 5.5 on my system. Plz help me to make a simple JSP program...:\apache-tomcat-5.5\lib.*; Also out the servlet api.jar file inside the lib folder
Advertisements
Java file create new file
Java file create new file This section demonstrates you how to create a new... of these tools, you can can easily create a new empty file. Now for this task, we have used the method createNewFile() of boolean type which creates a new empty file
To make java exe or runnable file
To make java exe or runnable file   Helo sir i make a java application.I need to help how run application direct in pc i.e how it packaged, .exe file or setup file
Create a new zip file in ZipArchive.
Creating a new Zip file in ZipArchive For creating zip file, use zipArchive () class. Create a new zip file in ZipArchive. Use the conditional statement... will generate a new zip file, in case of failure, it will print failed in creating
How To Create a New File
How To Create a New File In this section we will discuss about how to create a new file in Java. A Computer File is a storage of data. In this file we can.... Such as, File.createNewFile() method creates the new file. java.io.File creates the new
Java file new line
Java file new line In this section, you will learn how to write the text in new line of text file. Description of code: The package java.io.* has provide... main(String[] args) throws Exception { File f = new File("C:/file.txt
How to make a file in java
Description: This example demonstrate how to make a file and write string in it. To create a file in java we use the File Class. The instance of the File class is immutable that means the pathname represented by the File object
To Determine whether the Session is New or Old
To Determine whether the Session is New or Old       In this program we are going to make one servlet on session in which we will check whether the session is new or old
Write Text To File In New Line.
Write Text To File In New Line. In this tutorial you will learn how to write text into file in a new line. When you are writing in a file you may be required... bw = null; try { File file = new File("newLineFileWriter.txt
How to write file text In New Line
How to write file text In New Line  Hi friends, How to write file... you went new text in new line. For this we created a new text file named... to write file text in New line in Java
Create new file in java
Create new file in java We are going to discuss how to create new file in java... file location in a System. We have created a new file fl.createNewFile() method... CreateFile { public static void main(String[] t) { File fl = new File("c
How to make a gzip file in java.
Make a gzip file from any given file. In this tutorial, we will discuss how to create GZIP file by using GZIPOutputStream class. ... {       File oldfile = new File(sourcefile
How to create a new text file that contains the file names of the copied files in a new directory? - Java Beginners
How to create a new text file that contains the file names of the copied files in a new directory?  Okay so my question is: How to create a new text file that contains the file names of the copied files in a new directory
creating new file with File class - JSP-Interview Questions
creating new file with File class   I have a file uploading concept in my project. For that, while creating a new file is it necessary to give... of FileOutputStream class. If we give the path as from the file uploading location will it work
How to make a servlet to automatically call another servlet at some time instant.
How to make a servlet to automatically call another servlet at some time instant.  Can some one assist me How to make a servlet to automatically call another servlet at some time instant. currently I have a single servlet which
add a new wcf service code to TFS and make it available to create an MSI. of its
add a new wcf service code to TFS and make it available to create an MSI. of its  i need to add a new wcf service in the existing TFS and create... that the setup folder recognizes it to create its setup file(.msi
servlet file upload
servlet file upload  please tell me the complete code to upload a file on localhost using servlet
Download file - JSP-Servlet
Servlet download file from server  I am looking for a Servlet download file example
Java append new node to XML file
Java append new node to XML file In this tutorial, you will learn how to append new node to xml file. Sometimes there is a need to append a new XML node to the xml file. Here is an xml file where we are going to append a new node
Java file new directory
Java file new directory In this section, you will learn how to create a new... { public static void main(String args[]) { File file = new File("Hello... provides various useful tools that has made the file handling easier. Programming
new
new   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType...; and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException
How To Make Executable Jar File For Java P{roject - Java Beginners
How To Make Executable Jar File For Java P{roject   Hello Sir I want Help to make Executable File for java Project How I can Make it?  Hi...(); File folder = new File("C:\\html"); File[] files
How to make a list from file text in J2ME - Java Beginners
How to make a list from file text in J2ME  I was trying to make a method that read file from text and make a list of it, I have tried ReadHelpText method and want to make some improvement, I've tried like this private String
files that are present in any folder , how to make it clickable downloadble file in php
files that are present in any folder , how to make it clickable downloadble file in php   files that are present in any folder , how to make it clickable downloadble file in php
make java application faster. - JSP-Servlet
make java application faster.  Hello, I am Dipti.I am working.... The application is quite slow I want to make it faster. Can u please suggest me what to do to make the application faster. Waiting for your solution Thanks
how to make session timeout programatically - JSP-Servlet
how to make session timeout programatically  hi, i have a login page with username and password. how to make session timeout for 10minutes... to make session timeout programatically, you can use the method
How to make auto number? - JSP-Servlet
How to make auto number?  Dear, my friend... I really need your help.... I want to ask you, how to make auto number in mysql database? The format that I want is: ======> 00010809, 00020809, 00030809, etc 0001 = auto
new
new    hi i am jane pls explain the difference between string greeting = good morning string greeting = new string ("good morning
new
new    hi i am jane pls explain the difference between heap memory and stack memory
new
new  hi the difference between string sname = good morning string sname =new("good morning
Advertisements
 

 

 

DMCA.com