DWR(Direct Web Remoting)配置
xml 散布
配置实体类
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://directwebremoting.org/schema/dwr30.dtd">
<dwr>
<!--修改该文件必须重启应用服务器-->
<allow>
<!--Interact交互控件-->
<create creator="new" javascript="SpiritInteractAction">
<param name="class" value="com.sinitek.spirit.webcontrol.interact.SpiritInteractAction"/>
</create>
<!--说明,如果dwr返回的对象或者list是一个bean,请在这里设置,重启服务器-->
<!--start 对象转换器-->
<convert converter="exception" match="java.lang.Exception"/>
<convert converter="bean" match="java.lang.StackTraceElement"/>
<convert converter="bean" match="com.sinitek.spirit.webcontrol.demo.*"/>
<convert converter="bean" match="com.sinitek.base.metadb.config.impl.*"/>
<convert converter="bean" match="com.sinitek.base.metadb.*"/>
<convert converter="bean" match="com.sinitek.spirit.webcontrol.tree.*"/>
<convert converter="bean" match="com.sinitek.spirit.webcontrol.table.*"/>
<convert converter="bean" match="com.sinitek.spirit.webcontrol.autocomplete.*"/>
<convert converter="bean" match="com.sinitek.spirit.webcontrol.selector.*"/>
<!--end 对象转换器-->
</allow>
<!--签名说明,dwr方法里的参数,是集合而且集合里的对象不是基本类型,必须要在此说明,请在这里设置,重启服务器-->
<signatures>
<![CDATA[
import java.util.Map;
import java.util.List;
import org.directwebremoting.io.FileTransfer;
import com.sinitek.spirit.webcontrol.form.SpiritFormAction;
SpiritFormAction.callFileSubmit(String, String, Map, String[],FileTransfer[],HttpServletRequest);
]]>
</signatures>
</dwr>
web.xml配置过滤
<!--Dwr配置-->
<servlet>
<servlet-name>spirit</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>allowScriptTagRemoting</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>config-pub</param-name>
<param-value>/WEB-INF/framework/dwr-spirit.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>classes</param-name>
<param-value>java.lang.Object</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
<init-param>
<param-name>
org.directwebremoting.extend.Remoter
</param-name>
<param-value>com.sinitek.sirm.common.support.dwr.DWRFilterRemoter</param-value>
</init-param>
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>pollAndCometEnabled</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>spirit</servlet-name>
<url-pattern>/dwrspirit/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>allowScriptTagRemoting</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>config-pub</param-name>
<param-value>/WEB-INF/dwr.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>classes</param-name>
<param-value>java.lang.Object</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
<init-param>
<param-name>
org.directwebremoting.extend.Remoter
</param-name>
<param-value>com.sinitek.sirm.common.support.dwr.DWRFilterRemoter</param-value>
</init-param>
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>pollAndCometEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>fasle</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
引入dwr的js和
java方法
public Object callSubmit(String clazz, String methodName, Map<String, String> map, HttpServletRequest request)
调用方法SpiritFormAction.callSubmit(className, method, param,{
callback:exceptionHandler,async:async}
dwr可以做请求校验
dwr.engine.setHeaders({"_ssid_":"${_ssid_}"});
dwr.engine.setErrorHandler(function(message, ex) {
});
document.reload = function (reload) {
return function () {
document.location.assign(sirm.appendssid(document.location.href));
};
}(document.reload);
设置请求时用的参数<c:set var="_innerheadinclude_" value="1" scope="request"/>