1、首先需要引入dwr.jar包到工程中的lib中;
2、在web.xml中配置dwr,如下:
<!-- DWR配置 -->
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>scriptCompressed</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
3、然后在WEB-INF下创建一个dwr.xml,并在里面将调用处理类配置,例如:
<dwr>
<allow>
<convert match="com.po.OneSearchDto" converter="bean">
<param name="include" value="resname,resid"></param>
</convert>
<create javascript="GetDataBaseRes" creator="new">
<param name="class" value="com.util.GetDataBaseRes"></param>
<include method="getDataBaseRes"/>
</create>
</allow>
</dwr>
4、然后在需要调用的jsp中,将调用处理js类引入,如下:
<%
String contextPath = request.getContextPath();
%>
<script type='text/javascript' src='<%=contextPath %>/dwr/interface/GetDataBaseRes.js'></script>
<script type='text/javascript' src='<%=contextPath %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=contextPath %>/dwr/util.js'></script>
调用的js例子如下:
function query(){
var keyWord = document.getElementById("keyWord").value;
var dataStr = "";
var arr = document.getElementsByName("checkboxData");
for(var i=0;i<arr.length;i++){
if(arr[i].checked){
dataStr+=","+arr[i].value;
}
}
GetDataBaseRes.getDataBaseRes(keyWord,dataStr,disPoseRes);
}
function disPoseRes(str){
alert(str);
}
5、如果需要在dwr调用类中获得session,或者request,如下:
jsp中如何调用dwr
最新推荐文章于 2020-12-20 04:01:19 发布