I am trying to add the data to the database which the user inputs from the form, it only adds the one which is specified in the film object. I'm not sure what the problem is here, can someone help please.
What I have tried:
I have sorted out the form and url and also called the java file. I have also created film object ad called the insertFilm method which adds the data to the database. It's only adding the one in the film object and not the one which has been inserted in the form.
The film object which it keeps adding to the database:
Film f = new Film(123456, "Wars", 2011, "Peter Jackson","100", "5 ");
This is the film object which it keeps adding to the database. I don't want this being added, I would like the one added in the form.
Create-film.java file:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
FilmDAO film = new FilmDAO();
ArrayList<Film> FilmList = FilmDAO.getAllFilms();
for (int i=0; i<FilmList.size(); i++ ) {
Film oneFilm = FilmList.get(i);
System.out.println(oneFilm.toString());
System.out.println("All data displayed successfully");
}
System.out.println("Testing the insert film");
Film f = new Film(123456, "Wars", 2011, "Peter Jackson","100", "5 ");
try {
FilmDAO.insertFilm(f);
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("DEBUG: Film Successfully inserted");
Html file:
<!DOCTYPE html>
<html>
<head>
<!--- Creating a heading for the form to create new film in the application -->
<h1>INSERT A FILM</h1>
<title>Form to create a new film</title>
<link rel="stylesheet" href="css/styles.css" type="text/css" />
</head>
<body>
<form action="ControlInsertFilm" method="POST">
<label for="id">ID</label> <input name="id" /> <br /> <label
for="title">title</label> <input name="title" /> <br /> <label
for="year">year</label> <input name="year" /> <br /> <label
for="director">director</label> <input name="director" /> <br /> <label
for="stars">stars</label> <input name="stars" /> <br /> <label
for="review">review</label> <input name="review" /> <br /> <input
type="submit" value="Submit" />
</form>
</body>
</html>