Розробка Web-проектів із використанням Spring Framework 2008 (Курс “Інформаційні технології”)

  • Published on
    18-Dec-2015

  • View
    217

  • Download
    0

Embed Size (px)

Transcript

  • Slide 1
  • Web- Spring Framework 2008 ( )
  • Slide 2
  • Spring - 20082 Spring Framework ! Framework , (, , ) , . ( Framework), , .
  • Slide 3
  • Spring - 20083 Spring EJB ?
  • Slide 4
  • Spring - 20084 Spring EJB ?
  • Slide 5
  • Spring - 20085 Spring Framework 1. Spring (Core Spring) : (Light-Weight) Framework; (Light-Weight) (Container ) -' (Business Objects) . (, J2EE- , Heavy-Weight J2EE . ). 2. Core Spring ( ) IoC-. 3. (POJO POJI ). Spring ( Spring) . , Spring POJO (Plain Old Java Object) POJI (Plain Old Java Interface).
  • Slide 6
  • Spring - 20086 Spring: POJO (Plain Old Java Object) POJI (Plain Old Java Interface). POJO POJI , Unit-, TDD (Test Driven Development). TheServlet ( Non-POJO, HttpServlet): class TheServlet extends HttpServlet{ } Unit- Web/Application , (deployment) , HttpServlet , . EJB.
  • Slide 7
  • Spring - 20087 Spring Framework Web (http://www.springframework.org/documentation)
  • Slide 8
  • Spring - 20088 Spring Model-View-Controller Spring Framework Web- ( Smalltalk) Model-View-Controller (MVC). MVC- Struts, WebWork . Spring . ( , ' Model , ' View , ' Controller .) View.
  • Slide 9
  • Spring - 20089 Spring Web MVC
  • Slide 10
  • Spring - 200810 Web- Java Java- HTML- println(). Model 1: JavaServer Pages (JSP) HTML- () Java- (). Model 2: Java- + JSP c Web-, JSP HTML-. Model 2 Model-View-Controller. Web- Spring Web MVC Framework , (generic servlet) DispatcherServlet FrontControler. , - .
  • Slide 11
  • Spring - 200811 Spring Web MVC (http://www.springframework.org/documentation)
  • Slide 12
  • Spring - 200812 Spring Web MVC Agile Java Development with Spring, Hibernate and Eclipse By Anil Hemrajani............................................... Publisher: Sams Pub Date: May 09, 2006 Print ISBN-10: 0-672-32896-8 Print ISBN-13: 978-0-672-32896-1 Pages: 360
  • Slide 13
  • Spring - 200813 Spring MVC Web. (workflow) (1/2) 1. Spring Front Controller, (Web Application). 2. Front Controller Handler Mapping, (map) --> . Handler Adapter. 3. , ' ModelAndView, Front Controller. 4. Front Controller, View Resolver, View (View Jsp, Velocity, Free marker ) . 12 3 4
  • Slide 14
  • Spring - 200814 Spring MVC Web. (workflow) (2/2) 1. Spring Front Controller, (Web Application). 2. Front Controller Handler Mapping, (map) --> . Handler Adapter. 3. , ' ModelAndView, Front Controller. 4. Front Controller, View Resolver, View (View Jsp, Velocity, Free marker ) . Front Controller ( DispatcherServlet) Handler Mapping, Handler Adapter Controller, ModelAndView View Resolver Spring MVC Web-
  • Slide 15
  • Spring - 200815 Front Controller (DispatcherServlet) web.xml ( web-)... springapp org.springframework.web.servlet.DispatcherServlet 1 springapp1 *.htm... ( Web -) Web Application /WEB-INF/springapp-servlet.xml
  • Slide 16
  • Spring - 200816 . web.xml... org.springframework.web.context.ContextLoaderListener contextConfigLocation /WEB-INF/ applicationContext.xml, /WEB-INF/ springapp-servlet.xml, /WEB-INF/ yet_appContext.xml... Listener Servlet (Context Loader ) . ( / WEB-INF/ applicationContext.xml.) -
  • Slide 17
  • Spring - 200817 Handler Mapping Handler Mapping (map) --> . Handler Mapping ( Spring! ): SimpleUrlHandlerMapping; BeanNameUrlHandlerMapping; CommonsPathMapHandlerMapping; ControllerClassNameHandlerMapping. ( org.springframework.web.servlet.handler ). .
  • Slide 18 Controller CalcS-servlet.xml ()">
  • Spring - 200818 SimpleUrlHandlerMapping. Controller CalcS-servlet.xml ()
  • Slide 19
  • Spring - 200819 BeanNameUrlHandlerMapping. Handler Mapping . web-. CalcS-servlet.xml () , Url- -.
  • Slide 20
  • Spring - 200820 Handler Adapter Handler Adapter ( Spring! ), framework: SimpleControllerHandlerAdapter ( , ); SimpleServletHandlerAdapter ; ThrowawayControllerHandlerAdapter ( org.springframework.web.servlet.handler ); ( interface HandlerAdapter org.springframework.web.servlet ).
  • Slide 21
  • Spring - 200821 ( Spring! )
  • Slide 22
  • Spring - 200822 AbstractController. Spring MVC Web Hello (Hello World !) Hello-servlet.xml () public class HelloController extends AbstractController{ public ModelAndView handleRequestInternal ( HttpServletRequest request, HttpServletResponse response){ return new ModelAndView("hello.jsp"); } Spring Application Hello World! hello.jsp AbstractController GET POST . ( extends ) AbstractController : public class HelloController implements Controller {...}
  • Slide 23
  • Spring - 200823 ModelAndView ModelAndView ( org.springframework.web.servlet ) . '- View Model. : ModelAndView mv = new ModelAndView(myView, myModel).
  • Slide 24
  • Spring - 200824 Model & View ModelAndView ( org.springframework.web.servlet ) . ' View Model. : ModelAndView mv = new ModelAndView(myView, myModel). View ( org.springframework.web.servlet.View ) View-: JSP, Excel, Pdf, Xslt, Free Marker, Html, Tiles, Velocity, Jasper Reports etc: return new ModelAndView("hello.jsp") ( ). ' Model ( org.springframework.ui.ModelMap) Map- ', , View : 1) Map myModel = new HashMap(); ModelAndView mv = new ModelAndView(myView, myModel). 2) Map myModel = new HashMap (); myModel.put("now", now);
  • Slide 25
  • Spring - 200825 ModelAndView. 1) ModelAndView mv = new ModelAndView("myView.jsp", "var", var); 2) ModelAndView mav = new ModelAndView("calc.jsp"); mav.addObject("z", z); mav.addObject("x", x); mav.addObject("y", y); // . 3) ModelAndView mv = new ModelAndView("myView"). myView () View (Logical View) View Resolver: Logical View Physical View Location. myView.jsp myView myView.xml + ...
  • Slide 26
  • Spring - 200826 AbstractController. ModelAndView. : Spring MVC Web Calc1
  • Slide 27
  • Spring - 200827 Controller. ModelAndView. : Spring MVC Web springapp public class InventoryController implements Controller { private ProductManager productManager; public ModelAndView handleRequest( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String now = (new java.util.Date()).toString(); Map myModel = new HashMap (); myModel.put("now", now); myModel.put("products", this.productManager.getProducts()); return new ModelAndView("hello", "model", myModel); } public void setProductManager( ProductManager productManager) { this.productManager = productManager; }
  • Slide 28
  • Spring - 200828 SimpleFormController , ( -). ' ( '): ' , ; , ' , (, ) ; , ' . ' SimpleForm Controller
  • Slide 29 ( springapp-servlet.xml)">
  • Spring - 200829 SimpleFormController. . (1/5) ' SimpleForm Controller priceincrease.jsp class PriceIncreaseFormController extends SimpleFormController ' "priceIncrease (class PriceIncrease) ( springapp-servlet.xml)
  • Slide 30
  • Spring - 200830 SimpleFormController. . (2/5) (Class PriceIncreaseFormController) public class PriceIncreaseFormController extends SimpleFormController { public ModelAndView onSubmit (Object command) throws ServletException { int increase = ((PriceIncrease) command).getPercentage();... return new ModelAndView(...); } protected Object formBackingObject ( HttpServletRequest request) throws ServletException { PriceIncrease priceIncrease = new PriceIncrease(); priceIncrease.setPercentage (20); return priceIncrease; } web-
  • Slide 31
  • Spring - 200831 SimpleFormController. . (3/5) (Class PriceIncrease) public class PriceIncrease { private int percentage; public void setPercentage(int i) { percentage = i; } public int getPercentage() { return percentage; } '
  • Slide 32 () springapp-servlet.xml ' ' ( ') View, ">
  • Spring - 200832 SimpleFormController. . (4/5) (- )... () springapp-servlet.xml ' ' ( ') View,
  • Slide 33 ............ priceincrease.jsp ' (' )">
  • Spring - 200833 SimpleFormController. . (5/5) ( priceincrease.jsp) ............ priceincrease.jsp ' (' )
  • Slide 34
  • Spring - 200834 View Resolver Spring View Resolver. , : org.springframework.web.servlet.ViewResolver
  • Slide 35
  • Spring - 200835 Spring : View Resolver View Resolver: InternalResourceViewResolver; BeanNameViewResolver; FreeMarkerViewResolver; JasperReportsViewResolver; ResourceBundleViewResolver; UrlBasedViewResolver; VelocityLayoutViewResolver; VelocityViewResolver; XmlViewResolver; XsltViewResolver.
  • Slide 36 JSTL (JSP Standard Tag Library)">
  • Spring - 200836 InternalResourceViewResolver. . . jsp- hello, priseincrease, , /WEB-INF/jsp/

Recommended

View more >