Documentos de Académico
Documentos de Profesional
Documentos de Cultura
contents
1 JSP Model 1
2 Page-View
3 Page-View with bean
4 JSP Model 2- Front Controller Pattern
5 How to make all the request go to one servlet ?
6 Identifying the Operation to Perform
7 Advantage of Front Controller Pattern
Know
response View
Model
request
Controller
request
Model
response View
http://myHost/myApp/servlets/myServlet?op=
createUser
• Through requested url paths : Servlet can
extract the requested operation's name from
the request URL. Servlet myServlet can
extract the requested operation's name from
the request URL.
String path=request.getServletPath();
• The BluePrints recommendation is to use
servlet mappings when they are available.
Servlet mappings provide the most flexible
way to control where to route URLs based on
patterns in the URL
RequestHandler
returns String handleRequest(HttpServletRequest req,
URL HttpServletResponse res) throws ServletException,
IOException
requests handleRequest()
Servlet
url Sub-Controller Class 1 Sub-Controller Class 2
RequestHandler
returns String handleRequest(HttpServletRequest req,
URL HttpServletResponse res) throws ServletException,
IOException
request handleRequest()
Servlet_
C url Emp_C Dept_C
EmpInsert data
Employee Department
DeptInsert
public class ControllerServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)throws IOException,
ServletException {
String path=request.getServletPath();
RequestHandler rh;
if(path.equals(“\empIns.html”)){
rh=(RequestHandler) new Emp_C;
else
if(path.equals(“\deptIns.html”)){
rh=(RequestHandler) new Dept_C;
String view=rh.handleRequest(request,response);
request.getRequestDispatcher(view).forward(request,respons
e);}
Model classes
Employee Department
-empno -deptName
-empName -managerid
-dept <Setters>
<Setters> <Getters>
<Getters> boolean insert()
boolean insert() static Vector findAll()
static Employee static Department
findByName(String name) findDept(String dept)
static Employee
findById(String id)
static Vector findAll()
view classes
Index InsertEmploye FindEmploy
e ee
InsertDepartme FindDepartme
nt nt
Controller classes
ControllerServlet
doGet()
EmpHandler DeptHandler