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

Please visit the following links:
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.