Hello.jsp

Hello.jsp
<html>
<head></head>
<title>Simple JSP example</title>
<body>
<h1>Hi!</h1>
Your browser is:
</body>
</html>
Page 1
Initialization.java
package ece1779.jsp;
import javax.servlet.http.*;
public class Initialization extends HttpServlet {
public void init() {
Movieplex moviedata = new Movieplex();
this.getServletContext().setAttribute("moviedata", moviedata);
}
}
Page 1
Movie.java
package ece1779.jsp;
public class Movie {
public int id;
public String name, rating, starring, director, synopsis, poster, url;
public Movie (int id, String name, String rating, String starring,
String director, String synopsis, String poster, String url) {
this.id = id;
this.name = name;
this.rating = rating;
this.starring = starring;
this.director = director;
this.synopsis = synopsis;
this.poster = poster;
this.url = url;
}
}
Page 1
Movieplex.java
package ece1779.jsp;
public class Movieplex {
public Theater [] theaters;
public Movie [] movies;
public Showtime [] showtimes;
public Movieplex() {
Theater [] t = {new Theater(1,"Canada Square","2190 Yonge Street, Toronto, ON, M4S2C6", "416-6460444"),
new Theater(2,"SilverCity","2300 Yonge Street, Toronto, ON, M4P1E4","416-5441236")
};
this.theaters = t;
Movie [] m = { new Movie(1,"Casino Royale", "PG-13","Daniel Craig, Judi Dench, Mads Mikkelsen, Eva Green, Jeffrey
Wright", "Martin Campbell", "James Bond's first 007 mission takes him to Madagascar, where he is to spy on a terrorist
Mollaka. Not everything goes as planned and Bond decides to investigate, independently of the MI6 agency", "http://
www.moviesonline.ca/movie-gallery/albums/userpics/poster_CasinoRoyalTeaserPoster.jpg", "http://www.sonypictures.com/movies/
casinoroyale/site/"),
new Movie(2,"Babel", "R", "Brad Pitt, Cate Blanchett, Gael Garcia Bernal, Elle Fanning, Koji Yakusho",
"Alejandro Gonzalez Inarritu", "In the remote sands of the Moroccan desert, a rifle shot rings out--detonating a chain of
events that will link an American tourist couple's frantic struggle to survive, two Moroccan boys involved in an accidental
crime, a nanny illegally crossing into Mexico with two American children and a Japanese teen rebel whose father is sought by
the police in Tokyo.", "http://z.about.com/d/movies/1/0/D/I/N/babelposter.jpg", "http://www.paramountvantage.com/babel/" )
};
this.movies = m;
Showtime [] s = { new
new
new
new
new
new
new
new
new
new
new
new
};
Showtime(1,1,1,2007,3,23,18,0,8),
Showtime(2,1,1,2007,3,18,20,0,8),
Showtime(3,1,1,2007,3,18,22,0,8),
Showtime(4,1,2,2007,3,23,18,0,8),
Showtime(5,1,2,2007,3,18,20,0,8),
Showtime(6,1,2,2007,3,18,22,0,8),
Showtime(7,2,1,2007,3,23,18,0,8),
Showtime(8,2,1,2007,3,18,20,0,8),
Showtime(9,2,1,2007,3,18,22,0,8),
Showtime(10,2,2,2007,3,23,18,0,8),
Showtime(11,2,2,2007,3,18,20,0,8),
Showtime(12,2,2,2007,3,18,22,0,8)
this.showtimes = s;
}
}
Page 1
Showtime.java
package ece1779.jsp;
public class Showtime {
public int id;
public int theaterid, movieid;
public int year, month, day;
public int hour, minute;
public float price;
// date
// time of day
public Showtime (int id,
int theaterid, int movieid,
int year, int month, int day,
int hour, int minute,
float price) {
this.id = id;
this.theaterid = theaterid;
this.movieid = movieid;
this.year = year;
this.month = month;
this.day = day;
this.hour = hour;
this.minute = minute;
this.price = price;
}
}
Page 1
Theater.java
package ece1779.jsp;
public class Theater {
public int id;
public String name;
public String address;
public String phone;
public Theater(int id, String name, String address, String phone) {
super();
this.id = id;
this.name = name;
this.address = address;
this.phone = phone;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
Page 1
ListTheaters.jsp
<!-- Begin: ListTheatres.jsp -->
<%@ page import="ece1779.jsp.Movieplex" %>
<%@ page import="ece1779.jsp.Theater" %>
<html>
<head>
<style>
tr {font-family:Helvetica, Arial; font-size:9pt;}
</style>
</head>
<body>
<h1> Movie Plex </h1>
<table>
</table>
</body>
</html>
Page 1
ShowTheater.jsp
<!-- Begin: ShowTheatre.jsp -->
<%@ page import="ece1779.jsp.Movieplex" %>
<%@ page import="ece1779.jsp.Theater" %>
<%@ page import="ece1779.jsp.Movie" %>
<%@ page import="ece1779.jsp.Showtime" %>
<%@ page import="java.util.Vector" %>
<!-<!--
Example of JSP Declaration -->
This code will be compiled outside the main JSP function -->
<%!
Theater getTheater(Movieplex moviedata, int tid) {
for (int i=0; i < moviedata.theaters.length; i++) {
if (moviedata.theaters[i].id == tid)
return moviedata.theaters[i];
}
return null;
}
Movie getMovie(Movieplex moviedata, int mid) {
for (int i=0; i < moviedata.movies.length; i++) {
if (moviedata.movies[i].id == mid)
return moviedata.movies[i];
}
return null;
}
Vector getMoviesForTheater(Movieplex moviedata, int tid) {
Vector movies = new Vector();
for (int i=0; i < moviedata.showtimes.length; i++) {
Showtime s = moviedata.showtimes[i];
if (s.theaterid == tid) {
Movie movie = getMovie(moviedata, s.movieid);
if (!movies.contains(movie)) {
movies.addElement(movie);
}
}
}
return movies;
}
%>
<html>
<head>
<style>
tr {font-family:Helvetica, Arial; font-size:9pt;}
</style>
</head>
<body>
<table>
<tr><td><hr /></td></tr>
<%
%>
<tr>
<td>
<%= theater.name %><br/>
<%= theater.address %><br />
<%= theater.phone %><br />
</td>
</tr>
<%
Vector movies = getMoviesForTheater(moviedata,tid);
for (int i=0; i < movies.size(); i++) {
Movie m = (Movie)movies.elementAt(i);
%>
<tr><td><hr /></td></tr>
<tr>
<td>
<%= m.name %><br/>
Director:<%= m.director %><br />
Synopsis:<%= m.synopsis %><br />
</td>
</tr>
<%
}
%>
</table>
</body>
</html>
Page 1