package servlets;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FormDataFileTableGenerator extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private final String INPUT_FILE_PATH = "output.txt";

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		
		PrintWriter output = response.getWriter();
		
		StringBuilder pageHTML = new StringBuilder(
			"<!DOCTYPE html>" +
			"<html>"+
			"<body>" +
				"<table border='1'>"
		);
		
		// Read from input file & add to page HTML
		BufferedReader bufferedReader = new BufferedReader(new FileReader(INPUT_FILE_PATH));
		String line = "";
		while ((line = bufferedReader.readLine()) != null) {
			pageHTML.append(
					"<tr><td>" + line + "</td></td>"	
			);
		}
		bufferedReader.close();
		
		pageHTML.append(
				"</table>" +
			"</body>" +
			"</html>");
		
		output.print(pageHTML);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}

@@ -130,24 +130,62 @@
 tWriter;%0D%0A%0D%0A
+import javax.servlet.ServletContext;%0D%0A
 import javax
@@ -204,32 +204,32 @@
 vletException;%0D%0A
-
 import javax.ser
@@ -466,66 +466,8 @@
 1L;%0D
-%0A%09%0D%0A%09private final String INPUT_FILE_PATH = %22output.txt%22;%0D
 %0A%0D%0A%09
@@ -636,49 +636,136 @@
 %0D%0A%09%09
-PrintWriter output = response.getWriter()
+ServletContext context = request.getServletContext();%0D%0A%09%09final String INPUT_FILE_PATH =  context.getRealPath(%22/%22) + %22output.txt%22
 ;%0D%0A%09
@@ -1288,20 +1288,66 @@
 ml%3E%22);%0D%0A
-
 %09%09%0D%0A
+%09%09PrintWriter output = response.getWriter();%0D%0A
 %09%09output

Generate INPUT_FILE_PATH from ServletContext real path