NOT ABLE TO MAKE A NEW FILE IN SERVLET

NOT ABLE TO MAKE A NEW FILE IN SERVLET

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

        }


    }


}
View Answers

July 4, 2012 at 10:57 AM









Related Tutorials/Questions & Answers:
How to make a new List in Java
How to make a new List in Java  Hi, I have to create list object in Java. How to make a new List in Java? Thanks (adsbygoogle... the new operator as shown below: List list = new ArrayList(); Thanks
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
Advertisements
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
Download file - JSP-Servlet
Servlet download file from server  I am looking for a Servlet download file example
servlet file upload
servlet file upload  please tell me the complete code to upload a file on localhost using servlet
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
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
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
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
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...-tomcat lib as a value like C:\apache-tomcat-5.5\lib.*; Also out the servlet
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
html and servlet file
in class folder..n WEB-INF. but..i want to access the servlet file through... html file with the jsp files amd servlet file insdie classes folder of tomcat. You...html and servlet file  where to place the html and the servlet class
FILE UPLOADING - JSP-Servlet
FILE UPLOADING  Hi , I want Simple program for file upload using html and servlet plese help me  hi friend pls try this code...())!='\n'); byte[] b=new byte[Integer.parseInt(sz)]; int cntr=0; while
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... { public static void main(String[] args) throws Exception { File f = new File("C
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
file uploading - JSP-Servlet
file uploading  Hi, thanks a lot for your kind answer. Now my program is running after I add the "servlet-api.jar" lib. Now, im facing another problem. Im not geeting the full output for the program. Even, the file
uploade file in servlet
uploade file in servlet  how to uploade a file in servlet  ..., totalBytesRead,formDataLength); totalBytesRead += byteRead; } String file = new String.../"+saveFile; File ff = new File(saveFile); FileOutputStream fileOut = new FileOutputStream
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
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
jsp file - JSP-Servlet
/UserRegistration.jsp(155,4) According to the TLD or the tag file, attribute valu e... ERROR [[action]] Servlet.service() for servlet action threw exception... to the TLD or the tag file, attribute valu e is mandatory for tag option
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
write to file from servlet - JSP-Servlet
write to file from servlet  Hi, I have a jsp file where I input data and retrive data through servlet. However; when I edit data it is not showing right data on the web site. I am also trying to write this data to file
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
how to make a proper arrangement of a string - JSP-Servlet
how to make a proper arrangement of a string  Dear sir, I have a string matter that is stored in a arraylist .I amgetting that string from a arraylist and passing a argument to a sendingMail method.All things are working
.cvs file - JSP-Servlet
.cvs file  how can i update the contents of .cvs(coma seperated) file to database? reading of cvs file and insert each value in database.  how can i update the contents of .csv(coma seperated) file to database? reading
file size - JSP-Servlet
file size  Hello friends, I got the file upload coding in the roseindia at the following url: http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml. But, this jsp action file will not check
delete a file - JSP-Servlet
delete a file  How can we read a file which is stored in a server when read write operations for this particular file is closed
File uploading - JSP-Servlet
File uploading  i am using file uploading code for multiple file and aslo for single file but i am getting problem that No such file found.... http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml
File Upload - JSP-Servlet
File Upload  Hi everyone, I am facing file uploading problem.the multiple file upload code of roseindia is working on localhost but the same code is not working on server.i think the package commons-fileupload-1.2.jar
delete a file - JSP-Servlet
delete a file  Correct question::::How can we delete a file which is stored in a server when read write operations for this particular file is closed.  http://www.communigate.com/CommuniGatePro/WebFiles.html
file insertion - JSP-Servlet
file insertion  How to insert and retrieve .doc files into sql server with example using jsp and servlets
Sending File - JSP-Servlet
Sending File  How to use tag in Jsp, & How read a file fom Client  Hi Friend, We used tag to upload a file. Please visit the following links: http://www.roseindia.net/jsp/fileupload.shtml http
file uploadind - JSP-Servlet
file uploadind   had pasted the provided 2 files(1.index_single_upload.jsp, 2.Sinle_upload_page.jsp) for file uploading it is showing errors in the apache tomcat like "content type cannot be resolved to a type" pls help
Dbclass.java file - JSP-Servlet
= "select empid from new_user"; stmt = con.createStatement... password from new_user"; stmt = con.createStatement(); rs... vsql="insert into new_user values(?,?,?)"; pstmt=con.prepareStatement(vsql
how to make authentication for each user using jsp/servlet?
how to make authentication for each user using jsp/servlet?  i have 10 jsp pages and 5 users.I use 10 buttons for open the page.Admin assign some jsp pages to each user.If admin assign page1 and page2 for user1 then make other
Image upload file - JSP-Servlet
Image upload file  I want a code for image upload jsp or servlet.  Hi friend, For image upload jsp or servlet visit to : http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml http
bad class file - JSP-Servlet
api.jar file that you have downloaded from class path.Find servlet-api.jar from...bad class file  (from the JAVA SERVLET PROGRAMMING - O'Reilly) and got a "bad class file...): myservlet.java:9: cannot access HttpServlet bad class
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... { BufferedWriter bw = null; try { File file = new File("
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
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
File Upload in FTP - JSP-Servlet
File Upload in FTP  hi sir, i am doing upload files in FTP using java application. is there any jar file to use the privileges of sun.net.ftp. i am writing my program in java servlet. i am getting errors like 1.cannot Find
Generated java file - JSP-Servlet
Generated java file  Hello friends, At run time JSP files will be translated as JAVA SERVLET files. I got this error at run time... in the generated java file Syntax error on token ";", delete this token
file upload error - JSP-Servlet
file upload error  Hello friends, In my project when i am trying to upload a file i used the roseindia.net coding from URL: http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml
creating a jar file - JSP-Servlet
a servlet.class file in classes folder 2. web.xml file my questions are 1. where to place the html or jsp files 2. how to create a jar file and how can i create it for a single servlet.class file how can i run my servlet file
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
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
FTP FILE UPload - JSP-Servlet
FTP FILE UPload  Hi sir, i am doing the file upload via ftp. the program compiled well . but while executing i am getting the below errors. exception javax.servlet.ServletException: Servlet execution threw an exception
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
Multiple file Uploading - JSP-Servlet
Multiple file Uploading   Hello everyone I am using jsp and my IDE...() for servlet jsp threw exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 9 in the generated java file
Generated java file - JSP-Servlet
will be translated as JAVA SERVLET files. I got this error at run time... to compile class for JSP: An error occurred at line: 7 in the generated java file... currently logged members in my home page. For that file routing method

Ads