This example shows a basic Java Servlet that shows a star list page.
-
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 using
git clone
- Open IntelliJ -> Import Project -> Choose the project you just cloned (The root path must contain the pom.xml!) -> Choose Import project from external model -> choose Maven -> Click on Finish -> The IntelliJ will load automatically
- For "Root Directory", right click "cs122b-project1-star-example" -> Mark Directory as -> sources root
- In
src/StarServlet.java
, make sure the mysql username ismytestuser
and password ismypassword
. - Also make sure you have the
moviedbexample
database. - To run the example, follow the instructions in canvas.
Export using maven in command line: Go to your project folder first, then do mvn clean
, then do mvn package
. Your WAR file should be in target/cs122b-project1-star-example.war
-
index.html
is a simple welcome page. Open the urllocalhost:8080/cs122b_fall22_project1_star_example
, if the welcome text shows up, then means that you have successfully deployed the project. -
StarServlet.java
is a Java servlet that talks to the database and get the stars data. It generates the HTML strings and write it to response. Open the urllocalhost:8080/cs122b_project1_star_example/stars
to see the page generated by this Servlet.