13.07.2015 Views

Integrating Servlets and JSP: The Model View Controller - Java ...

Integrating Servlets and JSP: The Model View Controller - Java ...

Integrating Servlets and JSP: The Model View Controller - Java ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Request-Based Data Sharing• ServletSomeBean value = LookupService.findResult(...);request.setAttribute("key", value);RequestDispatcher dispatcher =request.getRequestDispatcher("/WEB-INF/SomePage.jsp");dispatcher.forward(request, response);24• <strong>JSP</strong> 2.0${key.someProperty}• <strong>JSP</strong> 1.2 (Old!)Name chosen by the servlet.Name of accessor method, minus theword “get”, with next letter changedto lower case.Request-Based Data Sharing:Simplified Example• ServletCustomer myCustomer =Lookup.findCust(request.getParameter("customerID"));request.setAttribute("customer", myCustomer);RequestDispatcher dispatcher =request.getRequestDispatcher("/WEB-INF/SomePage.jsp");dispatcher.forward(request, response);• <strong>JSP</strong> 2.0${customer.firstName}Assume that the findCust methodh<strong>and</strong>les missing/malformed data.Note: the Customer class musthave a method called “getFirstName”.• <strong>JSP</strong> 1.225

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!