- Use the following script to create the
student
table
CREATE DATABASE prj301;
GO
USE prj301;
GO
CREATE TABLE student (
id INT PRIMARY KEY,
firstname VARCHAR(100),
lastname VARCHAR(100),
age INT
);
GO
INSERT INTO student (id, firstname, lastname, age) VALUES
(1, 'John', 'Doe', 20),
(2, 'John', 'Smith', 22),
(3, 'Alex', 'Johnson', 21),
(4, 'Emily', 'Williams', 19),
(5, 'Michael', 'Brown', 23);
GO
- Pull the prj301-demo2.
cd e:/Projects/prj302-demo-teacher
git pull
- Copy
e:/Projects/prj302-demo-teacher/prj301-demo2
to your development source - Add prj301-demo2 to NetBean, change database connection in DBUtils
Milestone 9: Develop StudentListServlet to show table of all Students with id, firstname, lastname, age
-
YOUR STEPS
- Write SQL to select all students with id, firstname, lastname, age
- Write code to execute the query (get connection from DBUtils)
- Present the result set in table with html tags
-
SUBMIT SCREENSHOTS:
9.1 List of student in Browser
9.2 Source code of StudentListServlet.java
-
YOUR STEPS
- In StudentListServlet, add a form at the top of page to submit keyword for searching
<form action=''> <input name=keyword type=text> <input type=submit value=Search> </form>
- Catching the value of the parameter
keyword
- Add
WHERE
condition to SQL withfirstname like ? or lastname like ?
- In StudentListServlet, add a form at the top of page to submit keyword for searching
-
SUBMIT SCREENSHOTS:
10.1 Searching student with nameJohn
. Screenshot the result in Browser
10.2 Source code of StudentListServlet.java
-
YOUR STEPS
- Create a link for header of Lastname with a href
?sortCol=lastname
- Catching the parameter sortCol to add to
ORDER BY
of the SQL
- Create a link for header of Lastname with a href
-
SUBMIT SCREENSHOTS:
11.2 Source code of StudentListServlet.java