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



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

Have Programming Question? Ask it here!
 
 
 


prateek gupta
NOT ABLE TO MAKE A NEW FILE IN SERVLET
1 Answer(s)      2 years and 2 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
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
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
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
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 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
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
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 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
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
uploade file in servlet
uploade file in servlet  how to uploade a file in servlet  ...,formDataLength); totalBytesRead += byteRead; } String file = new String(dataBytes..., boundaryLocation)).getBytes()).length; saveFile="C:/UploadedFiles/"+saveFile; File ff = new
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
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
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
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
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
.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
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
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
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
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
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
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
and writing to new file.  Hello, I would like to know how to write... stumped when it comes to reading the file and writing to a new file. My code... the input one."); }else{ loop=1;} Scanner IF = new Scanner(new File
 

 

 

DMCA.com