JavaScript(JFIS)

 

1 、返回上一页面
οnclick="window.history.back()"
 
2 Java 中输出 JavaScript
PrintWriter out = response.getWriter();
out.println( "<script language='javascript'>alert('Power name is not null !');window.history.back();</script>" );
out.close();
 
3 、“确定 / 取消”按钮
< a href = "#" onclick = " del( ${outers.itemid} ) " > < img border = "0" src = "images/del.gif" ></ a >
< script >
  function del(v) {  
 if (confirm( '确认要删除吗 ? 删除后数据不可恢复!' )== true ) {
<%--    触发Action的链接 --%>
url = "outer.do?method=outer_delet&outerId=" +v;
    window.location=url; }    
 else {
    return null ;
    }
    }
</ script >
 
4 、非空验证
function check() {       
        if (document.form1.payfieldName.value== "" ) {
                alert( '薪酬字段名称不能为空!!!' );
                document.form1.payfieldName.focus(); // payfieldName 是文本框的 ID
                return false ;
        }       
}
< html:form action = "/outer.do?method=outer_new" onsubmit = "return check()" >
5 在 textarea 的 onkeyup 中检查字数的 方法:
< script language = "javascript" type = "text/javascript" >
//控制textarea里的最大输入
function DjCheckMaxlength(oInObj)
{
    var iMaxLen = parseInt(oInObj.getAttribute( 'maxlength' ));
    var iCurLen = oInObj.value.length;
 
    if ( oInObj.getAttribute && iCurLen > iMaxLen )
    {
        oInObj.value = oInObj.value.substring(0, iMaxLen);
        alert( '您输入的字符超过最大限度!' );
    }
} //@ END OF DjCheckMaxlength()
</ script >
<textarea maxlength="80" οnkeyup="return DjCheckMaxlength(this);"></textarea>
 
6 、通过日历填写日期
<input name="starttime" type="text" class="tborder1" id="starttime" size="30" maxlength="20" onFocus="show_cele_date(starttime,'','',starttime)">
< script language = "javascript1.1" >
 
var date_start,date_end,g_object
var today = new Date();
var separator= "-" ;
var inover= false ;
 
//mode : 时间变换的类型 0- 1- 2- 直接选择月
function change_date(temp,mode)
{
        var t_month,t_year
    if (mode) {
        if (mode==1)
        t_month=parseInt(cele_date_month.value,10)+parseInt(temp,10);
        else
        t_month=parseInt(temp)
        if (t_month<cele_date_month.options(0).text) {
            cele_date_month.value=cele_date_month.options(cele_date_month.length-1).text;
            change_date(parseInt(cele_date_year.value,10)-1,0);
            }
        else{
            if (t_month>cele_date_month.options(cele_date_month.length-1).text) {
                cele_date_month.value=cele_date_month.options(0).text;
                change_date(parseInt(cele_date_year.value,10)+1,0);
                }           
            else
                { cele_date_month.value=t_month;
                 set_cele_date(cele_date_year.value,cele_date_month.value);               
                }
        }
    } 
    else{
        t_year=parseInt(temp,10);
       
        if (t_year<cele_date_year.options(0).text) {
            cele_date_year.value=cele_date_year.options(0).text;
            set_cele_date(cele_date_year.value,1);               
            }
        else{
            if (parseInt(t_year,10)>parseInt(cele_date_year.options(cele_date_year.length-1).text,10)) {
                cele_date_year.value=cele_date_year.options(cele_date_year.length-1).text;
                set_cele_date(cele_date_year.value,12);               
                 }           
            else
                { cele_date_year.value=t_year;
                 set_cele_date(cele_date_year.value,cele_date_month.value);               
                }
        }
    }
 
    window.cele_date.focus();
 
}
 
//初始化日期
function init(d_start,d_end)
{
     var temp_str;
     var i=0
     var j=0
     date_start= new Date(1980,7,1)
     date_end= new Date(2004,8,1)
     document.writeln( "<div name=/"cele_date/" id=/"cele_date/" style=/"display:none/"    style=/"LEFT: 69px; POSITION: absolute; TOP: 159px;Z-INDEX:99/" onClick=/"event.cancelBubble=true;/" onBlur=/"hilayer()/" onMouseout=/"lostlayerfocus()/">-</div>" );
     window.cele_date.innerHTML= "" ;
     temp_str= "<table border=/"1/" bgcolor=/"#DDDDDD/" bordercolor=/"white/"><tr><td colspan=7 οnmοuseοver=/"overcolor(this)/">" ;
     temp_str+= "<input type=/"Button/" value=/"<</" οnclick=/"change_date(-1,1)/" οnmοuseοver=/"getlayerfocus()/" style=/"color: #000099; background-color: #BFBFBF; cursor: hand/">-" ;
 
     temp_str+= ""
     temp_str+= "<select name=/"cele_date_year/" id=/"cele_date_year/" language=/"javascript/" οnchange=/"change_date(this.value,0)/" οnmοuseοver=/"getlayerfocus()/" οnblur=/"getlayerfocus()/" style=/"font-size: 9pt; border: 1px #666666 outset; background-color: #F4F8FB/">"
 
     for (i=1900;i<=2020;i++)
     {
             temp_str+= "<OPTION value=/"" +i.toString()+ "/">" +i.toString()+ "</OPTION>" ;
     }
     temp_str+= "</select>-" ;
     temp_str+= ""
     temp_str+= "<select name=/"cele_date_month/" id=/"cele_date_month/" language=/"javascript/" οnchange=/"change_date(this.value,2)/" οnmοuseοver=/"getlayerfocus()/" οnblur=/"getlayerfocus()/" style=/"font-size: 9pt; border: 1px #666666 outset; background-color: #F4F8FB/">"
 
     for (i=1;i<=12;i++)
     {
             temp_str+= "<OPTION value=/"" +i.toString()+ "/">" +i.toString()+ "</OPTION>" ;
     }
     temp_str+= "</select>-" ;
     temp_str+= ""
     temp_str+= "<input type=/"Button/" value=/">>/" οnclick=/"change_date(1,1)/" οnmοuseοver=/"getlayerfocus()/" style=/"color: #000099; background-color: #BFBFBF; cursor: hand/">" ;
 
     temp_str+= "</td></tr><tr><td οnmοuseοver=/"overcolor(this)/">"
     temp_str+= "<font color=red>日</font></td><td>" ;temp_str+= "一</td><td>" ; temp_str+= "二</td><td>" ; temp_str+= "三</td><td>"
     temp_str+= "四</td><td>" ;temp_str+= "五</td><td>" ; temp_str+= "六</td></tr>" ;
     for (i=1 ;i<=6 ;i++)
     {
     temp_str+= "<tr>" ;
        for (j=1;j<=7;j++) {
            temp_str+= "<td name=/"c" +i+ "_" +j+ "/"id=/"c" +i+ "_" +j+ "/" style=/"CURSOR: hand/" style=/"COLOR:#000000/" language=/"javascript/" οnmοuseοver=/"overcolor(this)/" οnmοuseοut=/"outcolor(this)/" οnclick=/"td_click(this)/">?</td>"
            }
     temp_str+= "</tr>"       
     }
     temp_str+= "</td></tr></table>" ;
     window.cele_date.innerHTML=temp_str;
}
function set_cele_date(year,month)
{
   var i,j,p,k
   var nd= new Date(year,month-1,1);
   event.cancelBubble= true ;
   cele_date_year.value=year;
   cele_date_month.value=month;  
   k=nd.getDay()-1
   var temp;
   for (i=1;i<=6;i++)
      for (j=1;j<=7;j++)
      {
      eval( "c" +i+ "_" +j+ ".innerHTML=/"/"" );
      eval( "c" +i+ "_" +j+ ".bgColor=/"#DDDDDD/"" );
      eval( "c" +i+ "_" +j+ ".style.cursor=/"hand/"" );
      }
   while (month-1==nd.getMonth())
    { j=(nd.getDay() +1);
      p=parseInt((nd.getDate()+k) / 7)+1;
      eval( "c" +p+ "_" +j+ ".innerHTML=" + "/"" +nd.getDate()+ "/"" );
      if ((nd.getDate()==today.getDate())&&(cele_date_month.value==today.getMonth()+1)&&(cele_date_year.value==today.getYear())) {
           eval( "c" +p+ "_" +j+ ".bgColor=/"#EFFB64/"" );
      }
      if (nd>date_end || nd<date_start)
      {
      eval( "c" +p+ "_" +j+ ".bgColor=/"#FF9999/"" );
      eval( "c" +p+ "_" +j+ ".style.cursor=/"text/"" );
      }
      nd= new Date(nd.valueOf() + 86400000)
    }
}
 
//s_object:点击的对象;d_start-d_end有效的时间区段;需要存放值的控件;
function show_cele_date(eP,d_start,d_end,t_object)
{
window.cele_date.style.display= "" ;
window.cele_date.style.zIndex=99
var s,cur_d
var eT = eP.offsetTop; 
var eH = eP.offsetHeight+eT; 
var dH = window.cele_date.style.pixelHeight; 
var sT = document.body.scrollTop;
var sL = document.body.scrollLeft;
event.cancelBubble= true ;
window.cele_date.style.posLeft = event.clientX-event.offsetX+sL-5; 
window.cele_date.style.posTop = event.clientY-event.offsetY+eH+sT-5;
if (window.cele_date.style.posLeft+window.cele_date.clientWidth>document.body.clientWidth) window.cele_date.style.posLeft+=eP.offsetWidth-window.cele_date.clientWidth;
if (d_start!= "" ) {
    if (d_start== "today" ) {
        date_start= new Date(today.getYear(),today.getMonth(),today.getDate());
    }else{
        s=d_start.split(separator);
        date_start= new Date(s[0],s[1]-1,s[2]);
    }
}else{
    date_start= new Date(1900,1,1);
}
 
if (d_end!= "" ) {
    s=d_end.split(separator);
    date_end= new Date(s[0],s[1]-1,s[2]);
}else{
    date_end= new Date(3000,1,1);
}
 
g_object=t_object
 
cur_d= new Date()
set_cele_date(cur_d.getYear(),cur_d.getMonth()+1);
window.cele_date.style.display= "block" ;
 
window.cele_date.focus();
 
}
function td_click(t_object)
{
var t_d
if (parseInt(t_object.innerHTML,10)>=1 && parseInt(t_object.innerHTML,10)<=31 )
{ t_d= new Date(cele_date_year.value,cele_date_month.value-1,t_object.innerHTML)
if (t_d<=date_end && t_d>=date_start)
{
var year = cele_date_year.value;
var month = cele_date_month.value;
var day = t_object.innerHTML;
if (parseInt(month)<10) month = "0" + month;
if (parseInt(day)<10) day = "0" + day;
 
g_object.value=year+separator+month+separator+day;
window.cele_date.style.display= "none" ; } ;
}
 
}
function h_cele_date()
{
window.cele_date.style.display= "none" ;
}
 
function overcolor(obj)
{
 if (obj.style.cursor== "hand" ) obj.style.color = "#FFFFFF" ;
 
 inover= true ;
 window.cele_date.focus();
 
}
 
function outcolor(obj)
{
        obj.style.color = "#000000" ;
        inover= false ;
 
}
 
function getNow(o) {
    var Stamp= new Date();
    var year = Stamp.getYear();
    var month = Stamp.getMonth()+1;
    var day = Stamp.getDate();
    if (month<10) {
        month= "0" +month;
    }
    if (day<10) {
        day= "0" +day;
    }
    o.value=year+separator+month+separator+day;
}
 
function hilayer()
{
        if (inover== false )
        {
                var lay=document.all.cele_date;
                lay.style.display= "none" ;
        }
}
function getlayerfocus()
{
        inover= true ;
}
function lostlayerfocus()
{
        inover= false ;
}
init();
//日历结束
</ script >
7 照片上传
SSh 框架下 Java 类中的方法
// upload
public void empImage(JfisEmployeeSys jfisEmpSysBean,String url){
       
           Session session = getSession();
              Transaction t =session.beginTransaction();
              // byte 型变量 初始化为空
              byte b[] = new byte [1];
              // 获得对象,给该对象图片字段赋值为 b
              jfisEmpSysBean.setEmpImage(Hibernate.createBlob(b));
              // 保存
              session.save(jfisEmpSysBean);
session.flush();
// 锁定,后更新
              session.refresh(jfisEmpSysBean, LockMode. UPGRADE ); 
              // 数据类型转换
              SerializableBlob sb = (SerializableBlob)jfisEmpSysBean.getEmpImage();
              java.sql.Blob wrapBlob = sb.getWrappedBlob();
              oracle.sql.BLOB blob = (oracle.sql.BLOB)wrapBlob;    
              try {
              // 建立输出流
              OutputStream out = blob.getBinaryOutputStream();
              // url 读入图片
              FileInputStream fis = new FileInputStream(url);
byte [] data = new byte [( int )fis.available()]; 
              fis.read(data);
              out.write(data);
              // 关闭
out.close();
              fis.close();
             
              } catch (Exception e){
                     e.printStackTrace();
              }
              session.flush();
              t.commit();
              session.close();
 
       }
   
 
//download
   public void empImageLoad(Long empId){
          // 获得 session 工厂
          Session session = getSession();
          Transaction t =session.beginTransaction();
          byte [] b = new byte [1];
           // ID 查找取出对象
          JfisEmployeeSys jfisEmpSysBean = (JfisEmployeeSys) getHibernateTemplate().get( "jfis.bean.JfisEmployeeSys" , empId);
         
          try {
// 创建输入流                 
InputStream inputStream = jfisEmpSysBean.getEmpImage().getBinaryStream();
// 新建 jpg 文件 路径为 F://picture//photo.jpg
                 FileOutputStream fileOutputStream = new FileOutputStream( "F://picture//photo.jpg" );
  // 将流里的内容写入文件
                 int len = 0;
                
                 while ((len = inputStream.read(b))!= -1){
                        fileOutputStream.write(b,0,len);
                 }
                 inputStream.close();
                 fileOutputStream.close();
                
          } catch (Exception e){
                 e.printStackTrace();
          }
          t.commit();
          session.close();
       }
 
<input type="file" name="empImage" id="empImage" size="23" οnchange="preview()"/>
 
function  preview()  
  {    
        var fileext=document.form1.empImage.value.substring(document.form1.empImage.value.lastIndexOf( "." ),document.form1.empImage.value.length)
        fileext=fileext.toLowerCase()
        if (fileext!= '.jpg' )
        {
            alert( " 对不起,系统不支持这种格式的照片,请修改图片格式后重新上传! " );
             document.form1.UpFile.focus();
        }
        else
        {
        document.getElementById( "image" ).innerHTML= "<img src='" +document.form1.empImage.value+ "' width=120 height=140 style='border:6px double #ccc'>"
          }        
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值