Question
I am usinig Netbeans will create a very simple partially-complete CRUD web application with a text file backend. The web application will allow the user
I am usinig Netbeans
will create a very simple partially-complete CRUD web application with a text file backend. The web application will allow the user to view (read) and edit (update) a note. (Create and delete will not be supported at this time.) A note will consist of a title, contents.
Architecture
Create a new web application called Week04Lab_SimpleNoteKeeper.
Add an empty file to /WEB-INF called note.txt which will be used for storing the note details. Add the following two lines to the file:
This is the title Contents go here
Add two JSPs named viewnote.jsp and editnote.jsp in /WEB-INF.
Add one servlet named NoteServlet.java in the package servlets.
Add one Java Bean named Note.java in the package domain.
The application has one URL ote that is mapped to NoteServlet
Requirements
- You must use a JavaBean to populate the view and edit pages.
- The JavaBean Note.java must have two strings: one for title and one for contents
- The servlet must use doGet() for displaying the form in the view or edit mode.
- The servlet must use doPost() for saving the form from the edit mode.
- The text file note.txt has exactly two lines. The first line is the title; the second line are the contents.
Hints
- Accessing files from a servlet is a bit different than from a Java application. In particular, the path of the file is relative to the project root. Here is some code to help you:
String path = getServletContext().getRealPath("/WEB-INFote.txt");
// to read files BufferedReader br = new BufferedReader(new FileReader(new File(path)));
// to write to a file PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(path, false)));
Do not hardcode any file paths in your project since it would not work on another computer.
The edit link can be written as and the edit parameter can be used to determine which JSP to display
Screenshots Screenshot when the application starts: Simple Note Keeper View Note Title: This is the title Contents: Contents go here Edit 1 of 3 User clicks edit: Simple Note Keeper Edit Note Title: This is the title Contents go here Contents: Save The edits the title and contents fields and clicks save: The edits the title and contents fields and clicks save: Simple Note Keeper View Note Title: Lab 3 Finished Contents: I finished lab 3. I learned about JavaBeans, JSPS, EL, and servlet routing. Edit Screenshots Screenshot when the application starts: Simple Note Keeper View Note Title: This is the title Contents: Contents go here Edit 1 of 3 User clicks edit: Simple Note Keeper Edit Note Title: This is the title Contents go here Contents: Save The edits the title and contents fields and clicks save: The edits the title and contents fields and clicks save: Simple Note Keeper View Note Title: Lab 3 Finished Contents: I finished lab 3. I learned about JavaBeans, JSPS, EL, and servlet routing. EditStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started