Skip to content
Snippets Groups Projects
Commit 51128f32 authored by Ehsan Soltan Mohammadzadeh (ehs227)'s avatar Ehsan Soltan Mohammadzadeh (ehs227)
Browse files

Replace WorkerReportServlet.java

parent f6993583
No related branches found
No related tags found
No related merge requests found
......@@ -27,11 +27,12 @@ public class WorkerReportServlet extends HttpServlet {
String report = request.getParameter("employee_report");
String filename = "";
File file = null;
try {
filename = "reports/" + name + " report.txt";
filename = request.getServletContext().getRealPath("") + "/" + name + "Report.txt";
File file = new File(filename);
file = new File(filename);
if (file.createNewFile()) System.out.println("Report created for " + name);
else System.out.println("Report already exists for " + name);
}
......@@ -40,11 +41,18 @@ public class WorkerReportServlet extends HttpServlet {
e.printStackTrace();
}
FileWriter writer = new FileWriter(filename);
try {
FileWriter writer = new FileWriter(file);
writer.write("Name: " + name + "\nLocation: " + location + "\nReport: " + report);
writer.close();
}
catch (IOException e) {
System.out.println("An error occured while trying to write to file.");
e.printStackTrace();
}
writer.write("Name: " + name + "\nLocation: " + location + "\nReport: " + report);
writer.close();
RequestDispatcher requestDispatcher = request.getRequestDispatcher(next_page);
requestDispatcher.forward(request, response);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment