
MY JSP CODE WITH THE JAVA CLASS: JSP CODE:
<html>
<body>
<%@ page language="java" import="java.io.*,data.*" %>
<%
String name=request.getParameter("name");
String mail=request.getParameter("email");
%>
<%
ServletContext sc=getServletContext();
String path=sc.getRealPath("mailList.txt");
musicja ja=new musicja();
ja.add(name,mail,path);
out.println("<h1>Ur name has been added successfully</h1>");
%>
</body>
</html>
JAVA CLASS FILE CODE:
package data;
import java.io.*;
import java.util.*;
public class musicja
{
public static void add(String name,String mail,String path) throws IOException
{
File f=new File(path);
PrintWriter p=new PrintWriter(new FileWriter(f,true));
p.println(name+"|"+mail+"|");
p.close();
}
}
My problem is that everytime i enter the data(via the browser),the data that i entere is printed on the text file(mailList.txt),but the data doesn't append,in the sense,everytime the previous data is deleted and the new data is printed in the file.Please do let me know if m missing something in the code or if i need to add something more.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.