Create a servlet survey on your favorite topic. Your survey needs to contain a m
ID: 3584115 • Letter: C
Question
Create a servlet survey on your favorite topic. Your survey needs to contain a minimum of three inputs. The survey input information will be saved to a file after each post. The response must then return the complete contents of your file including the latest post. Display your response in a tabled format and place each saved response in a separate table row. Name your data file "data.dat" and place it in the "C:Temp" directory. The name of your application directory is to be "Week_04" and your servlet name is to be "Survey". The following code is provided to get you started. import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class ServletReadWrite extends HttpServlet{ private String target = "localhost:8080"; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ PrintWriter out = response.getWriter(); printHeader(out); printForm(out); printFooter(out); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ final int BUFFERLENGTH = 41; String data = null; PrintWriter out = response.getWriter(); /* * Open for read write */ RandomAccessFile randomAccessFile = new RandomAccessFile("C:/Temp/RandomData3.dat", "rw"); StringBuffer buffer = new StringBuffer(request.getParameter("myName")); /* * Sets buffer length to a const length * Places a newline in the last position */ buffer.setLength(BUFFERLENGTH); buffer.setCharAt(BUFFERLENGTH - 1, ' '); /* * Seek tothe end of the file */ randomAccessFile.seek(randomAccessFile.length()); /* * Write string to file * * Using writeChars here will add additional spaces */ randomAccessFile.writeBytes(buffer.toString()); /* * Seek to the beginning of the file */ randomAccessFile.seek(0); printHeader(out); /* * Read file one line at a time */ while ((data = randomAccessFile.readLine()) != null){ out.println(data + ""); } /* * Close file */ randomAccessFile.close(); printForm(out); printFooter(out); } public void printHeader(PrintWriter out){ out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(" "); } public void printFooter(PrintWriter out){ out.println(" "); out.println(""); out.println(""); } public void printForm(PrintWriter out){ out.println(" "); out.println("Enter Name "); out.println(""); out.println(""); out.println(" "); } } "); } public void printFooter(PrintWriter out){ out.println("
Explanation / Answer
such a long question,i dont think anyone is gonna read it, so please rate me
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.