批量删除功能包括以下文件:
jsp页面:list.jsp

<%...@ page contentType="text/html; charset=utf-8" language="java" %>
<%...@ page import="java.util.Vector" %>
<%...@ page import="myclass.common.property.RetProperty" %>
<%...@ page import="myclass.common.property.ParProperty" %>
<jsp:useBean id="mLoad" class="myclass.message.MesLoad" scope="page" />

<%...@ include file="../common/com_config.jsp" %>
<script src="../voice_mail/js_css/voice.js" type="text/javascript"></script>
<%...
ParProperty ppro = new ParProperty();
ppro.setPNum(1);
ppro.setENum(10);
ppro.setType("1"); // 0:新闻;1:留言
Vector vec = mLoad.getList(ppro);
for (int i = 0; i < vec.size(); i++) {
RetProperty rpro = (RetProperty)vec.elementAt(i);
System.out.println(""+rpro.getId());
}
%>
<div id="right">
<div class="pro_search">
<img src="../common/image/net_2sub3_r2_c2.gif" />
</div>
<div class="voice_list">
<%...
if(vec.size()>0){
for (int i = 0; i < vec.size(); i++) {
RetProperty rpro = (RetProperty)vec.elementAt(i);
String ls_mesnum = rpro.getMesnum();//
String ls_type = rpro.getType();//
String ls_subject = rpro.getSubject();//
String ls_content = rpro.getContent();//
String ls_createtime = rpro.getCreatetime();//建档时间
String ls_createman = rpro.getCreateman();//建档人
%>
<ul>
<li><%... if(is_master_flag){ %><input type="checkbox" id="Check_message_<%=ls_mesnum%>" name="Check_message_<%=ls_mesnum%>" value="1" onchange="Add_message_bh('<%=ls_mesnum%>');" /><%... } %><%=i+1%>. 【 <%=ls_subject%> 】<font color="#0080FF"><b><%=ls_createman%></b></font> 说: <%=ls_content%></li>
<li style="text-align:right;"><%=ls_createtime%></li>
</ul>
<%...
}
if(is_master_flag){
%>
<div align="center">
<input type="button" value="删 除" onclick="Delete_message();" />
<input type="hidden" id="Choose_message_bh" name="Choose_message_bh" value="" />
</div>
<%...
}
}
%>
</div>
</div>
js脚本:voice.js
// JavaScript Document
function Add_message_bh(mes_bh)...{
var checkbox_obj = $("Check_message_"+mes_bh);
var add_num = "#"+mes_bh+"#";
var choose_bh = $F("Choose_message_bh");
if(checkbox_obj.checked && choose_bh.indexOf(add_num)<0)...{
if(choose_bh=="")...{
$("Choose_message_bh").value = add_num;
}else...{
$("Choose_message_bh").value = choose_bh + "," + add_num;
}
}else if(checkbox_obj.checked==false && choose_bh.indexOf(add_num)>=0)...{
choose_bh = choose_bh.replace(new RegExp(","+add_num),"");
choose_bh = choose_bh.replace(new RegExp(add_num+""),"");
choose_bh = choose_bh.replace(new RegExp(add_num),"");
$("Choose_message_bh").value = choose_bh;
}
}
function Delete_message()...{
var url = "../voice_mail/voice_manager.jsp";
var pars = "";
pars = ajaxaddpars_var("action",pars,"delete");
pars = ajaxaddpars_formtext("choose_bh",pars,"Choose_message_bh");
mynormalAjax(url,pars,"Ajax_noreturn_div");
}数据处理页面:voice_manager.jsp

<%...@ page contentType="text/html; charset=utf-8" language="java" %>
<%...@ page import="java.util.Vector" %>
<%...@ page import="myclass.common.property.MessProperty" %>
<%...@ page import="myclass.common.property.ParProperty" %>
<jsp:useBean id="mSave" class="myclass.message.MesSave" scope="page" />
<%...@ include file="../common/com_config.jsp" %>

<%...
String gs_action = CB.clearNull(request.getParameter("action"));
String gs_choose_bh = CB.clearNull(request.getParameter("choose_bh"));
%>
<%...
if("delete".equals(gs_action)){
String temp_choose_bh = gs_choose_bh.replaceAll("#","");
ParProperty ppro = new ParProperty();
ppro.setMesnum(temp_choose_bh);
MessProperty mpro = new MessProperty();
mpro = mSave.delete(ppro);
%>
<script language="javascript">...
alert("<%=mpro.getMessage()%>");
window.document.location.reload();
</script>
<%...
}
%>
java核心代码

public class MesSavePart ...{
protected void deleteMessage(Session hSession, ParProperty ppro)...{
String hqlQuery = "update Message set state='1' where mesnum in ("+ ppro.getMesnum() +") ";
Query query = hSession.createQuery(hqlQuery);
query.executeUpdate();
}
}

public class MesSave ...{
private MesSavePart msp = new MesSavePart();
public MessProperty delete(ParProperty ppro)...{
Session hSession = HibernateInit.Session();
MessProperty mpro = new MessProperty();

try ...{
hSession.beginTransaction().begin();
msp.deleteMessage(hSession, ppro);
hSession.beginTransaction().commit();
mpro.success();
} catch (RuntimeException e) ...{
hSession.beginTransaction().rollback();
System.out.println("删除信息出错!");
e.printStackTrace();
}
return mpro;
}
}
本文介绍了一种使用JavaScript和Java实现的批量删除功能,包括list.jsp页面、voice.js脚本、以及voice_manager.jsp数据处理页面的协同工作,重点在于Java核心代码的设计和应用。
3295

被折叠的 条评论
为什么被折叠?



