1) [20] write a Controller class using a servlet. Assume that your form has a te
ID: 3910496 • Letter: 1
Question
1) [20] write a Controller class using a servlet. Assume that your form has a textbox named soccerHeadCoach Text that is initial value is empty string. The form will also have a processButton,editButton and cancelButton. (skeleton code provided at bottom) The servlet will check for the following a. If the button named processButton was clicked i. If the textbox is null or empty string, send to edit jsp ii. If the textbox has a string with "Bielsa", send to bestcoachOffhePlanetjsp li. If the textbox has anything else, send to process.jsp b. If the button named editButton as clicked i. Redirect to edit, jsp c. If anything else is clicked (including cancelButton) i. Redirect to goodbye.jsp public class Controller extends HttpServlet protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOExceptionExplanation / Answer
Controller Class:
public class Controller extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String action = request.getParameter("action");
String text=request.getParameter("soccerHeadCoachText");
if ("processButton".equals(action)) { // action of processButton
if(text.equals("")) {
response.sendRedirect("edit.jsp"); //redirect to edit.jsp file
}
else if(text.contains("bielsa")) {
response.sendRedirect("bestCoachOfThePlanet.jsp"); //redirect to bestCoachOfThePlanet.jsp file
}
else if(text!=null) {
response.sendRedirect("process.jsp"); //redirect to process.jsp file
}
}
else if ("editButton".equals(action)) { //action of editButton
response.sendRedirect("edit.jsp"); //redirect to edit.jsp file
}
else if("cancelButton".equals(action)) { // action of cancelButton
response.sendRedirect("goodbye.jsp"); //redirect to goodbye.jsp file
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.