I have tried to look for answers else where on this website but i have not been able to find anything that helps me. When ever press the create actor button to send the information to a controller i always get "HTTP 404 Status - not found: The requested resource is not available" I was just wondering if any could help me sort out this frustrating problem
This is the code for my index.jsp where i submit the information
<!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
<title>Index Page</title>
</head>
<body>
<h1>Movie Example Index Page</h1>
<!--submit button goes to the controller-->
<form action="Controller" method="post">
<p>
ID <input TYPE = "text" name = "actorID"/>
Name <input TYPE ="text" name ="name"/>
Birth Year <input TYPE ="text" name ="birth_year"/>
<input TYPE="submit" value="Create Actor" />
</p>
</form>
</body>
</html>
And this is my Controller code
package MVC_Movie_Example;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Class definition
public class Controller extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
// Make an instance of a new actor
int id = Integer.parseInt(request.getParameter("actorID"));
String name = request.getParameter("name");
int birthYear = Integer.parseInt(request.getParameter("birth_year"));
Actor actor = new Actor(id, name, birthYear);
// Set the actor attribute within the request
request.setAttribute("theActor", actor);
// Send it on to a different View
request.getRequestDispatcher("outputView.jsp").forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}
The actor class code is
package MVC_Movie_Example; // Package declaration
// Class definition
public class Actor {
private int id;
private String name;
private int birthYear;
public Actor() {
} // Default constructor
// Value based constructor
public Actor(int externId, String externName, int externBirthYear) {
this.id = externId;
this.name = externName;
this.birthYear = externBirthYear;
}
// Actor id getter method
public int getId() {
return this.id;
}
// Actor id setter method
public void setId(int externId) {
this.id = externId;
}
// Actor name getter method
public String getName() {
return this.name;
}
// Actor name setter method
public void setName(String externName) {
this.name = externName;
}
// Other methods follow, including birthYear getter and setter
} // End of class definition
And finally this is the code for where the controller sends the output
<!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
<title>Movie View Example - Output View</title>
</head>
<body>
<h1>Movie View Example – Out View Page</h1>
<jsp:useBean id="actor" type="MVC_Movie_Example.Actor" scope="request" />
<table border="1">
<tr>
<th>ID</th>
<th>Actor Name</th>
<th>Year of birth</th>
</tr>
<tr>
<td><jsp:getProperty name= "theActor" property="id" /></td>
<td><jsp:getProperty name= "theActor" property="name" /></td>
<td><jsp:getProperty name= "theActor" property="birthYear" /></td>
</tr>
</table>
</body>
</html>