Ajax-DWR框架使用简介
Ajax-DWR框架使用简介
一般步骤:
1。将dwr.xml配置文件放在Web应用的WEB-INF目录下;
<dwr>
<allow>
<create creator="spring" scope="page" javascript="imageInfoService">
<param name="beanName" value="imageInfoService"/>
<include method="avalidateAddBizImage"/>
<include method="isWaterMarkPolicy"/>
</create>
</allow>
</dwr>
2.JSP文件的JS代码中调用DWR:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate"/>
<meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"/>
<link href="${ctx}/styles/imageRepository/common.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${ctx}/dwr/util.js"> </script>
<script type="text/javascript" src="${ctx}/dwr/engine.js"> </script>
<script type="text/javascript" src="${ctx}/dwr/interface/imageInfoService.js"></script>
<script>
<c:if test="${categoryIsNotExist == true}">
alert("该图片库分类已经不存在!");
</c:if>
function batchAddWaterMark() {
var chkbxNum= document.getElementsByName('categoryId');
var isChecked = false;
for (var i=0; i< chkbxNum.length; i++){
if (chkbxNum[i].checked == true) {
isChecked = true;
break;
}
}
if (!isChecked) {
alert("请选择要添加水印的图片库分类!");
return false;
}
<!--JavaScript代码调用AJAX框架DWR-->
imageInfoService.isWaterMarkPolicy("1",function(result){
if(result=='isWaterMarkPolicy'){
if(confirm("您确定进行此操作吗,将会把图片库中所有未加过水印的图片全部添加水印!")){
document.categoryForm.action = "${ctx}/imageRepository.do?method=batchAddWaterMark";
document.categoryForm.submit();
}
}else{
alert("无法添加水印,请先到企业设置――图片水印参数设置中进行设置!");
return false;
}
});
}
</script>
<div align="center"><input name="buttonDelete22" type="button" value="批量添加水印" class="buttonL" onclick="batchAddWaterMark();"/></div>
<div class="font_gray" style="margin-top:10px;">提示:上传图片前请先在“默认上传分类设置”中绑定图片库分类</div>
</div>
</body>
</html>
3.业务类
(1)接口类:
package com.sitechasia.ebiz.imagerepository.service;
import java.util.List;
import java.util.Map;
import com.sitechasia.ebiz.imagerepository.vo.ImageInfoVO;
import com.sitechasia.webx.core.service.IValueObjectBaseService;
import com.sitechasia.webx.core.support.Page;
public interface IImageInfoService extends IValueObjectBaseService<ImageInfoVO> {
/**
* 判断是否有水印策略
* @param hasAddWaterMark
* @return
*/
public String isWaterMarkPolicy(String hasAddWaterMark);
}
(2)实现类:
package com.sitechasia.ebiz.imagerepository.service.impl;
import java.awt.Image;
import java.awt.imag