在公司实习时做的短消息提醒模块部分程序

来源:互联网 发布:网络新词语大全2015 编辑:程序博客网 时间:2024/06/05 18:14

js内容如下:(其中多余的注释是自己有意留下的)

var myWindow;
function makeRequest(url) {
 http_request = false;
 if (window.XMLHttpRequest) {
  http_request = new XMLHttpRequest();
  if (http_request.overrideMimeType){
   http_request.overrideMimeType('text/xml');
  }
 } else if (window.ActiveXObject) {
  try{
   http_request = new ActiveXObject("Msxml2.XMLHTTP");
     }
  catch (e) {
    try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
   }
 }
 if (!http_request) {
  alert("您的浏览器不支持当前操作,请使用 IE 5.0 以上版本!");
  return false;
 }
 

//定义页面调用的方法init,不是init();没有();
 http_request.onreadystatechange = init;
 http_request.open('GET', url, true);

//禁止IE缓存
 http_request.setRequestHeader("If-Modified-Since","0");

//发送数据
 http_request.send(null);

//每60秒刷新一次页面
 setTimeout("makeRequest('"+url+"')", 15000);
}

function init() {
 if (http_request.readyState == 4) {
  str="";
  if (http_request.status == 0 || http_request.status == 200) {
   var result = http_request.responseText.toString();
   var myregex = new RegExp("noNewSms");
   //if(result==""){
    //result = "连接失败";
   // }
   if(myregex.test(result)){
     if((window.myWindow)&&(myWindow.closed==false))
       myWindow.close();
     }
   else{
   //}    
     str=newWindow(result);
   }
 document.getElementById ("sysTimeShow").innerHTML=str;
  }//else {//http_request.status != 200
   //alert("请求失败!");
  //}
 }
 }
 
var listSms =new Array();
var count;
 function newWindow(result){
   var splitArray = new Array();
   var regex=/#/;
   splitArray = result.split(regex);
   count=(splitArray.length-1)/6; //以#号作为分隔符
   var i=0;
   var j=1;
   while(i<count){
   var smsInfo = new Object();
   smsInfo.id=splitArray[i*5+j];
   smsInfo.userName=splitArray[i*5+j+1];
   smsInfo.content=splitArray[i*5+j+2];
   smsInfo.sendTime = splitArray[i*5+j+3];
   smsInfo.smsType = splitArray[i*5+j+4];
   result+="<br>id:#"+smsInfo.id+"<br>#name:"+smsInfo.userName+"<br>content:"+smsInfo.content+"<br>time:"+smsInfo.sendTime+"<br>type:"+smsInfo.smsType
   listSms[i]=smsInfo;
   i=i+1;
   j=j+1;
   }
   var height=105;
   var width=300;
   var top=screen.height-1.6*height;
   var left=screen.width-width-10;
   var feature="height="+height+",width="+width+",top="+top+",left="+left+"toolbar=no,menubar=no, scrollbars=no, resizable=no,location=no, status=yes";
   if((window.myWindow)&&(myWindow.closed==false))
    myWindow.close();
   myWindow =open('','mywin',feature);
   myWindow.opener=window;
   var windowHtml="<!DOCTYPE html PUBLIC /"-//W3C//DTD XHTML 1.0 Transitional//EN/" /"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd/">"
   windowHtml+="<html xmlns=/"http://www.w3.org/1999/xhtml/"><head><title>短消息</title><script type=/"text/javascript/" src=/"/OA/js/window.js/" charset=/"gb2312/"></script><link rel=/"stylesheet/" href=/"/OA/css/window.css/" type=/"text/css/" /></head><body>";
   windowHtml +="<div id='type'>你有"+count+"条未读短消息"+"&nbsp;&nbsp;&nbsp;类型:<em id='smsType'>"+listSms[count-1].smsType+"</em></div>";
   windowHtml +="<div id='secondP'><span id='userName'>"+listSms[count-1].userName+"</span><em id='id' style='display:none'>"+listSms[count-1].id+"</em><em id='sendTime'>"+listSms[count-1].sendTime+"</em></div>";
   windowHtml +="<div id='content'>"+smsInfo.content+"</div>";
   windowHtml +="<div id='footer' align='right'>"+"<a href='#'id='kown' onclick='window.kownSms();'>"+"我知道了"+"</a>&nbsp;"+"<a href='#' id='link' onclick='window.linkSms();'>"+"链接&nbsp;</a>"+"<a href='#' id='reply' onclick='window.replySms();'>"+"回复&nbsp;</a>"+"<a href='#'id='delete' onclick='window.deleteSms();'>"+"删除"+"</a>&nbsp;<a href='#' id='next' onclick='window.opener.change()'>下一条</a></div></body></html>";
   result+="<br>id:#"+listSms[count-1].id+"#<br>name:"+listSms[count-1].userName+"<br>content:"+listSms[count-1].content+"<br>time:"+listSms[count-1].sendTime+"<br>type:"+listSms[count-1].smsType;
   count=count-1;
   myWindow.document.write(windowHtml);
   myWindow.document.close();
   myWindow.focus();
   return result;

}

function change(){
var contentNode=myWindow.document.getElementById('content').firstChild;
count=count-1;
if(count>=0){
myWindow.document.getElementById('content').firstChild.data=listSms[count].content;
var currentNode=myWindow.document.getElementById('userName').firstChild;
currentNode.data=listSms[count].userName;
currentNode=myWindow.document.getElementById('sendTime').firstChild;
currentNode.data=listSms[count].sendTime.substring(2,21);
currentNode=myWindow.document.getElementById('smsType').firstChild;
currentNode.data=listSms[count].smsType;
currentNode=myWindow.document.getElementById('id').firstChild;
currentNode.data=listSms[count].id;


}
if(count<0)
myWindow.document.getElementById('next').style.display="none";
}
//windowHtml+="<script language='JavaScript'><!--function clock(){i=i-1;document.title='本窗口将在'+i+'秒后自动关闭';if(i>0)setTimeout('clock();',1000);else self.close();}var i=10;clock();//--></script>"
//windowHtml+="<div id='close' name='close'></div>";
//<script type='text/javascipt'><!--var splitArray="+splitArray+"; var count="+count-1+";function search(){";
//windowHtml+="count=count-1;if(count>=0){document.getElementById('content').value=splitArray[splitArray.length-4*count-1];document.getElementById('count').value=count+1;}}//--></script></head><body>";
//onclick='window.location='/OA/setSmsRead.do?smsId="+smsInfo.smsId+"'' style='display:none'style='display:none'
//myWindow.document.getElementById('content').firstChild.deleteData(0,4);
//currentNode.replaceData(0,currentNode.length,listSms[count].id);
//alert("#"+listSms[count].id+"#/narray0:"+currentNode.data);
//currentNode.deleteData(0,currentNode.length);
//currentNode.insertData(0,listSms[count].id);
//currentNode=currentNode.parentNode;
//currentNode=currentNode.nextSibing;
//currentNode=currentNode.firstChild;
//myWindow.document.getElementById('content').innerText=listSms[count].content;效果相同 

其中的action:CheckNewSms.java如下:

package com.struts.action;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.struts.servic.*;
import com.struts.domain.*;
/**
 *
 * @author afei
 *
 */
public class CheckNewSms extends Action {
 /*
  * 检验是不是有新的要提醒的短消息
  */
 private SmsService smsService;
 Sms upSms = new Sms();
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)throws Exception {
  String userName="";
  if(request.getSession().getAttribute("userName")!=null)
   {
  userName=request.getSession().getAttribute("userName").toString();
     List<Sms> smsNotRead=smsService.findNotReadSms(this.smsService.getUserInfoByUserName(userName).getUserId());
  List<SmsAndInfo> list = new ArrayList<SmsAndInfo>();
  if(smsNotRead.size() > 0){   
   for(Sms sms : smsNotRead){
    SmsAndInfo smsAndInfo = new SmsAndInfo();
       smsAndInfo.setFromName(this.smsService.getUserInfoByUserId(sms.getFromId()).getUserName());
       smsAndInfo.setSms(sms);
       smsAndInfo.setSmsInfo(this.smsService.findBySmsId(sms.getSmsId()));
       smsAndInfo.setToName(this.smsService.getUserInfoByUserId(sms.getFromId()).getUserName());
       smsAndInfo.setStrSmsType(this.smsService.getSmsTypeStr(this.smsService.findBySmsId(sms.getSmsId()).getSmsType()));
       list.add(smsAndInfo);
   }
   request.setAttribute("list", list);
   
   
  }
  }
  return mapping.findForward("ajaxReq");}
    
 public SmsService getUserService() {
  return smsService;
 }

 public void setSmsService(SmsService smsService) {
  this.smsService = smsService;
 }

}
window.js弹出窗口JS如下:

function kownSms(){
window.location="/OA/updateReadSms.do?id="+document.getElementById('id').innerText;
}
function deleteSms(){
alert("你确定要删除此短消息吗?");
window.location="/OA/deleteSms.do?id="+document.getElementById('id').firstChild.data;

}
function replySms(){
window.open('/OA/WebPage/notify/sendSms.jsp?receive='+document.getElementById('userName').firstChild.data,'secondWin');
}
function linkSms(){
var _type=document.getElementById("smsType").firstChild.data;
var thirdWindow;
if(_type==" 邮件"||_type.substring(2,4)=="邮件")
     thirdWindow=window.open('/OA/WebPage/notify/querySms.jsp','thirdWin');
 else if(_type==" 短消息"||_type.substring(2,5)=="短消息")
     thirdWindow=window.open('/OA/smsReceivedBox.do','thirdWin');
   else if(_type==" 考勤"||_type.substring(2,4)=="考勤")
      thirdWindow=window.open('/OA/WebPage/notify/querySms.jsp','thirdWin');
        else
         alert("类型:"+_type+"不能处理");
      thirdWindow.focus();        
}

window.css如下:

/* CSS Document */
html,body {
 margin:0;
 padding:0;
 color:#0000FF;
 font-size: 12px;
 scrollbar-face-color: #b0d7f6;
 scrollbar-highlight-color: #ffffff;
 scrollbar-shadow-color: #284b9a;
 scrollbar-3dlight-color: #284b9a;
 scrollbar-arrow-color: #70068e;
 scrollbar-track-color: #e2f3f1;
 scrollbar-darkshadow-color: #ffffff;
 overflow-x: hidden;
}
a:link {
 text-decoration: none;
 color: #000000;
 font-family: "宋体"
}

a:visited {
 text-decoration: none;
 font-family: "宋体";
 color: #000000
}

a:hover {
 text-decoration: underline;
 font-family: "宋体";
 color: #0000ff
}
#type{
 background-color: #DCF2FC;
 font-size: 14px;
 margin-top:0px;
 color: #000000;
 border-bottom: 1px;
 border-bottom-color: #000000;
}
#type em{
font-style:normal;
font-size:14px;

}

#secondP{
    background-color: #FFFFFF;
 margin-bottom: 10px; 
   
}
#secondP #userName{
 font-size: 14px;
 text-decoration: underline; 
}
#content{
 position:fixed;
 background-color: #FFFFFF;
 color: #000000;
 font-size: 12px;
 height:46px;
 bottom: 20px;
}

#footer{
 background-color: #E2E8FA;
 text-align: right;
 font-style: normal;
 color: #0000FF;
 font-size: 12px;
 bottom: 0px; 
}
#secondP #sendTime{
text-align:left;
font-style:normal;
font-size:12px;
padding-left:10px;
}

sms.css(是短消息一部分)如下:

html,body {
 margin:0;
 padding:0;
 color:#000;
 font-size: 12px;
 scrollbar-face-color: #b0d7f6;
 scrollbar-highlight-color: #ffffff;
 scrollbar-shadow-color: #284b9a;
 scrollbar-3dlight-color: #284b9a;
 scrollbar-arrow-color: #70068e;
 scrollbar-track-color: #e2f3f1;
 scrollbar-darkshadow-color: #ffffff;
 overflow-x: hidden;
}
p {margin:1em 0;}

a:link {
 text-decoration: none;
 color: #000000;
 font-family: "宋体"
}

a:visited {
 text-decoration: none;
 font-family: "宋体";
 color: #000000
}

a:hover {
 text-decoration: underline;
 font-family: "宋体";
 color: #0000ff
}
.page{
margin-right:10%;
margin-left:10%;
text-align:right;
}
.page ul{
 margin: 0;
 }
.page ul li {
 float:left;
 list-style: none;
 margin-left: 3px;
 padding: 6px 0 2px 0px;
 border-bottom: dashed 1px #d8e4f0;
 overflow: hidden;
}
.table{
word-break:break-all;
word-wrap:break-word;
margin:0px auto #aaa;
border-collapse:collapse;
font-family:Arial, Helvetica, sans-serif;
table-layout:fixed;
}
.table th,td{
border:1px solid
}
.table thead th{
border-bottom:2px solid #3D580B;
background-color:#8fc629;
color: #fff;
padding:10px 0px;
}
.table th{
background-color:#f2f4b9;
}
.table tfoot td{
border-width:0px;
text-align:right;
font-size:12px;
color:#777;
}
.table caption{
font-weight:bold;
padding:6px 0px;
color:#3d580b;
font-size:24px;
}
.table tbody{
background-color:#ffd56c;
}
.table tbody th{
background-color:#ffe8ae;

}
.ft{
text-align:center
}
.ft table{
width:80%;
font-size:12px;
color:#333333;
border-collapse:collapse;
text-align:left;
}
.ft table th,td{
padding:3px;
border-top:1px solid #bbb;
padding:10px;
}
.ft table th{
border-left:none;
text-align:left;
}
.ft table td{
border-right:none;
border-left:none;
}
.ft table tbody{
background-color:#FFFFFF;
}
.ft .tleft{
    width:30%;
 font-family: Georgia, "Times New Roman", Times, serif;
 font-size: 14px;
 font-style: normal;
 font-weight: bold;
}

原创粉丝点击