Java Beans and Controller Helpers
87
{ address = “Edit.jsp”; } RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); }
Complete Controller Helper The next listing shows the complete code for a simple controller helper. It is using the bean from the DefaultValidate application – the controller helper has imported the class for the bean. The JSPs for the application will be rewritten in the next section. Since a relative reference is being used in the address for the JSP, it is assumed that the controller will be mapped to the directory that contains the JSPs. package ch3.reorganised; import import import import import
java.io.IOException; javax.servlet.RequestDispatcher; javax.servlet.ServletException; javax.servlet.http.HttpServletRequest; javax.servlet.http.HttpServletResponse;
import ch3.defaultValidate.RequestDataDefault; public class ControllerHelper extends HelperBase { protected RequestDataDefault data = new RequestDataDefault(); public ControllerHelper(HttpServletRequest request, HttpServletResponse response) { super(request, response); } public Object getData() { return data; } protected void doGet() throws ServletException, IOException { request.getSession().setAttribute(“helper”, this); data.setHobby(request.getParameter(“hobby”)); data.setAversion(request.getParameter(“aversion”)); String address; if (request.getParameter(“processButton”) != null) {