In the blog reposted in the previous article, it is the Getting Started tutorial of DWR. Through the previous blog, we can get a preliminary understanding of the principles of DWR and the process of using DWR.
In the previous blog, the classes exposed are DWR and new are instantiated. How can I use the instantiated classes in spring containers?
The procedure is as follows:
In the previous blog, you do not need to change the specific exposure class and JSP.
First: since spring is used, configure spring in Web. xml.
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <servlet> <servlet-name>dwr</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>crossDomainSessionSecurity</param-name> <param-value>false</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param></web-app>
2. Modify the DWR. xml file:
<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype DWR public "-// getahead limited // DTD direct Web remoting 2.0 //" http://getahead.org/dwr/dwr20.dtd "> <DWR> <allow> <! -- Service is used on front-end JS --> <create creator = "Spring" javascript = "service"> <Param name = "beanname" value = "servicemanager"/> </create> </allow> </DWR>
Third: configure the spring core configuration file:
<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean name="serviceManager" class="com.test.Service"/> </beans>
OK. This is OK, which is very simple.
The value in the beanname parameter in DWR. XML is the same as the bean name in the spring configuration file.
Each method called in DWR. xml needs to be created. The Creator in "CREATE" has multiple types, which are new by default.
It can also be the Spring framework, struts, JSF, and pageflow. If you are interested, try again.