废话不多说具体代码如下所示:
BoxDAO;
import com.rc.daoimpl.R_mailBoxDAOimpl;
import com.rc.dbutil.sqltools;
import com.rc.entity.MailBox;
import com.rc.entity.R_user;
import com.rc.entity.TreeNodes;
import com.rc.util.Page;
import com.rc.util.PageUtil;
public class MailBoxServlet extends HttpServlet {
/**
* The doGet method of the servlet.
* * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ @Override public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { response.setContentType("text/html;charset=utf-8"); String action =request.getParameter("action"); HttpSession hs = request.getSession(false); //读取登录人员session R_user cuser =(R_user)hs.getAttribute("user"); PrintWriter out = null; R_mailBoxDAO mb = new R_mailBoxDAOimpl(); boolean b = true; if("page".equals(action)){//查询所有 int pageNumber = 0; String PageNumberstr = request.getParameter("pageNumber");//从页面获取的当前页 int count =mb.getcount(); if(PageNumberstr == null||"".equals(PageNumberstr)){ pageNumber= 1; }else{ pageNumber = Integer.parseInt(PageNumberstr);//否则强转 } List pages = new ArrayList();
Page page = PageUtil.createPage(5,count,pageNumber);
pages.add(page);
List mailBoxlist = mb.getcostList(page);
JSONObject obj = new JSONObject();//定义一个json对象
obj.put("mailBox",mailBoxlist);
obj.put("Page",pages);
out = response.getWriter();
out.write(obj.toString());
}else if("delete".equals(action)){//删除操作
String mid = request.getParameter("id");
JSONObject obj = new JSONObject();
b =mb.delete(Integer.parseInt(mid));//用boolean接收
obj.put("biaozhi",b);
out = response.getWriter();
out.write(obj.toString());
}else if("edit".equals(action)){//弹出编辑页面
}else if("tedit".equals(action)){//提交编辑信息
}else if("pldelete".equals(action)){//批量删除
JSONObject obj = new JSONObject();
String deleteidlist = request.getParameter("deleteidlist");
String[] item = deleteidlist.split(",");
for (int i = 0; i < item.length; i++) {
b =mb.delete(Integer.parseInt(item[i]));
}
obj.put("biaozhi",b);
out = response.getWriter();
out.write(obj.toString());
}else if("tree".equals(action)){
List treelist = mb.getnodes();
JSONObject obj = new JSONObject();//定义一个json对象
obj.put("treelist",treelist);
out = response.getWriter();
out.write(obj.toString());
}else if("save".equals(action)){
String id = request.getParameter("id");
String zhuti = request.getParameter("zhuti");
String content = request.getParameter("content");
MailBox mail = new MailBox();
mail.setS_id(Integer.parseInt(id));//收件人
mail.setS_name(sqltools.findusername(Integer.parseInt(id)));//收件人姓名
mail.setP_name(cuser.getUsername());//发件人姓名
mail.setP_id(cuser.getId());
mail.setContent(content);
mail.setTitle(zhuti);
b = mb.addmailBox(mail);
JSONObject obj = new JSONObject();
obj.put("biaozhi",b);
out = response.getWriter();
out.write(obj.toString());
}
}
/**
* The doPost method of the servlet.
* * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ @Override public void doPost(HttpServletRequest request,IOException { this.doGet(request,response); } }
* * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ @Override public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { response.setContentType("text/html;charset=utf-8"); String action =request.getParameter("action"); HttpSession hs = request.getSession(false); //读取登录人员session R_user cuser =(R_user)hs.getAttribute("user"); PrintWriter out = null; R_mailBoxDAO mb = new R_mailBoxDAOimpl(); boolean b = true; if("page".equals(action)){//查询所有 int pageNumber = 0; String PageNumberstr = request.getParameter("pageNumber");//从页面获取的当前页 int count =mb.getcount(); if(PageNumberstr == null||"".equals(PageNumberstr)){ pageNumber= 1; }else{ pageNumber = Integer.parseInt(PageNumberstr);//否则强转 } List
* * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ @Override public void doPost(HttpServletRequest request,IOException { this.doGet(request,response); } }
dao层
Box;
import com.rc.entity.TreeNodes;
import com.rc.util.Page;
public interface R_mailBoxDAO {
public List getcostList(Page page); //获取全部的邮件
public int getcount();//获取数目
public boolean delete(Integer id); //删除
public boolean add(MailBox mail);//写信
public boolean update(Integer id);//修改
public List getnodes();//树
public boolean addmailBox(MailBox mail);//添加邮件
}
daoimpl
sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.sqlException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.rc.dao.R_mailBoxDAO;
import com.rc.dbutil.sqltools;
import com.rc.entity.MailBox;
import com.rc.entity.TreeNodes;
import com.rc.util.Page;
import com.rc.util.StringUtil;
public class R_mailBoxDAOimpl implements R_mailBoxDAO {
boolean b=true;
Connection cnn = null;
PreparedStatement ps = null;
ResultSet rs= null;
Statement st = null;
String sql="";
@Override
public List getcostList(Page page) {
List mailBoxlist = new ArrayList();//定义一个数组
int startsize = page.getCurrentPage()*page.getEverPage();
int endsize = (page.getCurrentPage()-1)*page.getEverPage()+1;
sql = "select * from (select a1.*,rownum rn from (select * from mailBox order by m_id desc) a1 WHERE rownum<="+startsize+") where rn>="+endsize+"";
try{
rs =sqltools.excuteQuery(sql,null);
while(rs.next()){
MailBox mailBox = new MailBox();
mailBox.setMid(rs.getInt("m_id"));
mailBox.setP_name(rs.getString("p_name"));
mailBox.setS_name(rs.getString("r_name"));
mailBox.setStatus(rs.getString("r_status"));
mailBox.setContent(rs.getString("r_content"));
mailBox.setTitle(rs.getString("r_title"));
mailBox.setR_time(StringUtil.TimetoString(rs.getDate("r_time")));
mailBoxlist.add(mailBox);
}
}catch(Exception e){
sqltools.close(rs,st,cnn);
}
return mailBoxlist.size()==0 ? null:mailBoxlist;
}
@Override
public int getcount() {
int count =0;
sql = "select count(*) from mailBox";
try{
cnn = sqltools.getConnection();
ps = cnn.prepareStatement(sql);
rs = ps.executeQuery();
if(rs.next()){
count = rs.getInt(1);
}
}catch(Exception e){
e.printStackTrace();
}finally{
sqltools.close(rs,ps,cnn);
}
return count;
}
@Override
public boolean delete(Integer id) {
sql="delete from mailBox where m_id=?";
try{
cnn=sqltools.getConnection();
ps=cnn.prepareStatement(sql);
ps.setInt(1,id);
ps.executeUpdate();
}catch(Exception e){
b=false;
e.printStackTrace();
}finally{
sqltools.aclose(rs,cnn);
}
return b;
}
@Override
public boolean add(MailBox mail) {
return false;
}
@Override
public boolean update(Integer id) {
return false;
}
@Override
public List getnodes() {//得到树节点
String sql = "select * from tree_table order by nid ";
cnn = sqltools.getConnection();
ArrayList treelist = new ArrayList();
try {
ps = cnn.prepareStatement(sql);
rs =ps.executeQuery();
while (rs.next()){
TreeNodes node = new TreeNodes();
node.setNid(rs.getInt("nid"));
node.setParentId(rs.getInt("parentid"));
node.setNodeName(rs.getString("nodename"));
treelist.add(node);
}
} catch (sqlException e) {
e.printStackTrace();
}finally{
sqltools.aclose(rs,cnn);
}
return treelist;
}
@Override
public boolean addmailBox(MailBox mail) {
sql = "insert into mailBox(m_id,p_name,r_name,p_id,r_id,r_content,r_title,r_send,r_status,r_time) values(mailBox_id_seq.nextval,?,sysdate)";
try{
cnn =sqltools.getConnection();
ps = cnn.prepareStatement(sql);
ps.setString(1,mail.getP_name());
ps.setString(2,mail.getS_name());
ps.setInt(3,mail.getP_id());
ps.setInt(4,mail.getS_id());
ps.setString(5,mail.getContent());
ps.setString(6,mail.getTitle());
ps.setString(7,"0");//是否发送
ps.setString(8,"3");//是否读取
ps.executeUpdate();
}catch(Exception e){
b = false;
e.printStackTrace();
}finally{
sqltools.aclose(rs,cnn);
}
return b;
}
}
jsp页面
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
My JSP 'mailBox.jsp' starting page
<Meta http-equiv="pragma" content="no-cache">
<Meta http-equiv="cache-control" content="no-cache">
<Meta http-equiv="expires" content="0">
<Meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<Meta http-equiv="description" content="This is my page">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
删除">
全选主题邮件内容
删除" class="btn btn-info" style="margin-top:50px;">
邮件" class="btn btn-primary btn-bg pull-right" style="margin-top:50px;">
Box" name="qx" onclick="quanxuan(this)">全选邮件内容
删除" class="btn btn-info" style="margin-top:50px;">
邮件" class="btn btn-primary btn-bg pull-right" style="margin-top:50px;">
Box" name="qx" onclick="quanxuan(this)">全选邮件内容
Enterprise Java Beans(EJB)是一个创建高度可扩展性和强大企业级应用程序的开发架构,部署在兼容应用程序服务器(比如 JBOSS、Web Logic 等)的 J2EE 上。
删除" class="btn btn-info" style="margin-top:50px;">
邮件" class="btn btn-primary btn-bg pull-right" style="margin-top:50px;">
Box" name="qx" onclick="quanxuan(this)">全选邮件内容
js
0){
$("input[name='deleteCusersid']").each(function(){
if($(this).prop("checked")){//如果要未选中的 ==false 就可以了
//ids += $(this).val()+",";
checkedList.push($(this).val());
}
});
swal({ title: "你确定要删除这"+checkedList.length+"行?",//text: "You will not be able to recover this imaginary file!",确定删除!",function(isConfirm){
if (isConfirm) {
var action = "pldelete";
$.ajax({
type : "post",a:Math.random(),deleteidlist:checkedList.toString()},"批量删除成功","success");
$("input[name='deleteCusersid']").prop("checked",false);//将其他有对号的清除
$("input[name='qx']").prop("checked",false);//将全选的对号清除
$("#list").empty();
page1();
//window.location.reload();
}else{
swal("Deleted!","error");
$("input[name='qx']").prop("checked",false);
$("input[name='deleteCusersid']").prop("checked",false);
}
});
}else{
swal("失败!","你必须选择至少一行进行该操作!","info");
}
}
function quanxuan(){//全选与全不选
if($("input[name='qx']").prop("checked")){
var checkBox = $("input[name='deleteCusersid']");
checkBox.prop("checked",true);
}else{
var checkBox = $("input[name='deleteCusersid']");
checkBox.prop("checked",false);
}
}
function addmail(){//写邮件
$("#btn_submit").click(function(){
var id = $("#menu_parent").val();
var zhuti = $("#zhuti").val();//获取主题
var content = $("#editor_id").val();//获取内容
if(zhuti==""||id==""){
if(zhuti==""){
swal("主题不能为空");
}else{
swal("收件人不能为空");
}
return false;
}else{
var action = "save";
$.ajax({
url: "MailBoxServlet",data : 'json',type : "post",data :{action:action,id :id,content :content,zhuti :zhuti,a : Math.random()},success : function(data){
if(data !=null){
var d= eval('('+data+')');
if(d.biaozhi){
swal("邮件编写成功");
}else{
swal("邮件编写失败");
}
}
$("#zhuti").val(""); //关闭的时候将所有的值制空
$("#setvalue").val("");
KindEditor.instances[0].html('');//专门的将textarea值置空0表示第一个KindEditor编辑器对象
$("#list").empty();//置空
page1();//异步刷新页面
}
});
}
//swal("关闭");
});
$("#btn_close").click(function(){
$("#zhuti").val(""); //关闭的时候将所有的值制空
$("#setvalue").val("");
KindEditor.instances[0].html('');//专门的将textarea值置空0表示第一个KindEditor编辑器对象
swal("关闭");
});
$("#send").click(function(){
swal("发送成功");
});
}
function initTree(){//初始化树
var action = "tree";
mydtree = new dTree('mydtree','${pageContext.request.contextPath}/style/default/images/dtree/','no','no');
mydtree.add(0,-1,"根目录","javascript:setvalue('0','根目录')","_self",true);
$.ajax({
url: "MailBoxServlet",success : function(data){
if(data !=null){
$.each(eval("(" +data+ ")").treelist,function(index,item){
var id =item.nid;
var pid = item.parentId;
var nodesname = item.nodeName;
mydtree.add(id,pid,nodesname,"javascript:setvalue('"+id+"','"+nodesname+"')",false);
});
//document.write(mydtree);
//将树添加到指定div(jQuery)
$("#treediv").html(mydtree.toString());
}
}
});
}
function shouwtree(){
$("#setvalue").click(function(){
$("#treediv").show();
});
}
function setvalue(id,name){
$("#setvalue").val(name);
$("#menu_parent").val(id);
$("#treediv").hide();
}
function page1(){
var pageNumber = 1;//默认初始页为第一页
var action = "page";//定义一个要进入的条件
$.ajax({//ajax请求
url: "MailBoxServlet",data :'json',type: "Post",pageNumber:pageNumber,//参数
success : function(data){//请求成功的方法
if(data !=null){
$.each(eval("(" + data + ")").mailBox,function (index,item) { //遍历返回的json
var html = " 删除";
html2=" 删除";
html2="
"
+""
+"
首页";
case "prev":
return "上一页";
case "next":
return "下一页";
case "last":
return "末页";
case "page":
return page;
}
},onPageClicked: function (event,originalEvent,type,page) {
$("#list").empty();
$.ajax({
url: "MailBoxServlet?pageNumber=" + page,data:{action:"page",success: function (data1) {
if (data1 != null) {
$.each(eval("(" + data1 + ")").mailBox,item) { //遍历返回的json
var html = ""
+""
+"
以上所述是小编给大家介绍的BootStrap实现邮件列表的分页和模态框添加邮件的功能。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持。
原文链接:https://www.f2er.com/bootstrap/45186.html