Integrate ZK with Spring MVC 3"
From Documentation
Line 10: | Line 10: | ||
=Setup the sample project= | =Setup the sample project= | ||
+ | In this article, we use Eclipse with m2eclipse plugin to create a new ZK Maven project, check the installation guide [[ZK_Installation_Guide/Quick_Start/Create_and_Run_Your_First_ZK_Application_with_Eclipse_and_Maven|here]]. | ||
+ | *First, we need to add Spring MVC dependency in the '''pom.xml''' file. | ||
+ | <source lang="xml"> | ||
+ | <!-- Spring MVC dependency --> | ||
+ | <dependency> | ||
+ | <groupId>org.springframework</groupId> | ||
+ | <artifactId>spring-webmvc</artifactId> | ||
+ | <version>3.1.2.RELEASE</version> | ||
+ | </dependency> | ||
+ | <!-- ZK dependency --> | ||
+ | <!-- ommitted --> | ||
+ | </source> | ||
+ | *Then, define SpringMVC <tt>DispatherServlet</tt> in '''web.xml''' file. | ||
+ | <source lang="xml"> | ||
+ | <!-- Spring MVC servlet --> | ||
+ | <servlet> | ||
+ | <servlet-name>springmvc</servlet-name> | ||
+ | <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | ||
+ | <load-on-startup>1</load-on-startup> | ||
+ | </servlet> | ||
+ | <servlet-mapping> | ||
+ | <servlet-name>springmvc</servlet-name> | ||
+ | <url-pattern>/</url-pattern> | ||
+ | </servlet-mapping> | ||
+ | <!-- ZK servlet --> | ||
+ | <!-- ommitted --> | ||
+ | </source> | ||
+ | *Finally, create a '''[servlet-name]-servlet.xml''' file under ''WEB-INF'' folder. Note that the file name pattern must match the servlet name defined in web.xml, in this sample the file name is '''springmvc-servlet.xml'''. In this file we can define the ViewResolver. | ||
+ | <source lang="xml"> | ||
+ | <beans ...> | ||
+ | <mvc:annotation-driven /> | ||
+ | <mvc:resources location="/images/" mapping="/img/**" /> | ||
+ | |||
+ | <context:component-scan base-package="demo.controller.springmvc" /> | ||
+ | <context:component-scan base-package="demo.data.service" /> | ||
+ | |||
+ | <bean id="jsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | ||
+ | <property name="prefix" value="/WEB-INF/" /> | ||
+ | <property name="suffix" value="" /> | ||
+ | </bean> | ||
+ | </beans> | ||
+ | </source> | ||
=Communiation between Spring MVC and ZK MVVM= | =Communiation between Spring MVC and ZK MVVM= |
Revision as of 03:15, 7 November 2012
Author
Vincent Jian, Engineer, Potix Corporation
Vincent Jian, Engineer, Potix Corporation
Date
November 06, 2012
November 06, 2012
Version
ZK 6.0.2/6.5.0 , Spring MVC 3.1.2
ZK 6.0.2/6.5.0 , Spring MVC 3.1.2
Introduction
Spring MVC is a request-based Model-View-Controller web framework. It is easy to define page flow with Spring MVC. However, when the website is getting complex, it is hard to maintain the page flows. Thus, it is not a bad idea to implement some part of functions by component-based (ajax-based) framework like ZK framework to reduce the page flows. This article will demonstrate how to communite between Spring MVC to ZK MVVM with a simple shopping cart sample.
Setup the sample project
In this article, we use Eclipse with m2eclipse plugin to create a new ZK Maven project, check the installation guide here.
- First, we need to add Spring MVC dependency in the pom.xml file.
<!-- Spring MVC dependency -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<!-- ZK dependency -->
<!-- ommitted -->
- Then, define SpringMVC DispatherServlet in web.xml file.
<!-- Spring MVC servlet -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- ZK servlet -->
<!-- ommitted -->
- Finally, create a [servlet-name]-servlet.xml file under WEB-INF folder. Note that the file name pattern must match the servlet name defined in web.xml, in this sample the file name is springmvc-servlet.xml. In this file we can define the ViewResolver.
<beans ...>
<mvc:annotation-driven />
<mvc:resources location="/images/" mapping="/img/**" />
<context:component-scan base-package="demo.controller.springmvc" />
<context:component-scan base-package="demo.data.service" />
<bean id="jsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value="" />
</bean>
</beans>
Communiation between Spring MVC and ZK MVVM
Spring MVC Controller to ZK MVVM
ZK MVVM to Spring MVC Controller
Consolution
Download
Comments
Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License. |