This example shows how JSP works independently.
-
login to mysql as a root user
local> mysql -u root -p
-
create a test user and grant privileges:
mysql> CREATE USER 'mytestuser'@'localhost' IDENTIFIED BY 'My6$Password'; mysql> GRANT ALL PRIVILEGES ON * . * TO 'mytestuser'@'localhost'; mysql> quit;
local> mysql -u mytestuser -p
mysql> CREATE DATABASE IF NOT EXISTS moviedbexample;
mysql> USE moviedbexample;
mysql> CREATE TABLE IF NOT EXISTS stars(
id varchar(10) primary key,
name varchar(100) not null,
birthYear integer
);
mysql> INSERT IGNORE INTO stars VALUES('755011', 'Arnold Schwarzeneggar', 1947);
mysql> INSERT IGNORE INTO stars VALUES('755017', 'Eddie Murphy', 1961);
- clone this repository
- open Intellij -> Import Project -> Import Project
(choose the project you just clone)
-> Click onFinish
. - Open
src/main/webapp/index.jsp
. Make sure you have themoviedbexample
database. - In Tomcat Deployment Configuration, make sure the application context is: /cs122b-project2-jsp-example
- To run the example, follow the instructions in canvas.
index.jsp
dynamically generates the html page with Java API. It is requested as a static resource, rather than a servlet sample we have seen before.
The .jsp file is requested directly.