applet+ajax

appFileList.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="bean" uri="/WEB-INF/struts-bean.tld" %> 
<%@taglib prefix="logic" uri="/WEB-INF/struts-logic.tld" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>文件列表</title>
<script type="text/javascript">
 //check all checkbox or reset all checkbox
 function   checkList(objBtn,strID)  
   {  
       var   state   =   objBtn.getAttribute("checked");   //if checkbox is checked,state is true,else state is false
       if   (!state)  
     state   =   0;  
      objBtn.value="全选";
        state   =   state   ==   0?   1:   0;  
        objBtn.setAttribute("checked",   state);  
    
       var   elements   =   objBtn.form.elements;   //get all checkBox
       for   (var   i=0;   i   <   elements.length;   i++)  
       {  
     if   (elements[i].id.indexOf(strID)   ==   0)   //all the checkbox which name's contain strID
      elements[i].checked   =   state;   //checkBox's checked property is true or false
       }  
       if(state){
      
        objBtn.value="取消";//if checkbox is checked,objBtn's value="取消",else objBtn's value="全选"
       }
      
   }
  
   function confirmDelete(text,action){
    //var deleteText="确认删除吗?一旦删除,不可恢复";
    if(window.confirm(text)){
     var table_name="AppFile";
    var redirectUrl="/appFileManage/appFileList.jsp";
  document.appFileFrm.action="changePage.html?action="+action+"&table_name="+table_name+"&redirectUrl="+redirectUrl;
  //alert(document.packetFrm.action);
  //document.packetFrm.action="/webOta/findChangePacketPage.html";
  document.appFileFrm.method="post";
  document.appFileFrm.submit();
    }
    return false;
   }
   function changePage(ac){
  var table_name="AppFile";
    var redirectUrl="/appFileManage/appFileList.jsp";
  document.appFileFrm.action="changePage.html?ac="+ac+"&table_name="+table_name+"&redirectUrl="+redirectUrl;
  //alert(document.packetFrm.action);
  //document.packetFrm.action="/webOta/findChangePacketPage.html";
  document.appFileFrm.method="post";
  document.appFileFrm.submit();
 }
</script>
<script type="text/javascript">
  var req=false;
  var which;
  var apduText;
  var bar_color = 'gray';

        var span_id = "block";

        var clear = "&nbsp;&nbsp;&nbsp;"
  var multiApdu;
  var result="<br>";
  function sendApdu(url){
  /**
  max apdu byte is 45k
  if applet size is too large to download time will become long,so server's loader to big
  **/
  
  
  var idsString = getIds();
  //alert("idsString="+idsString);
  /**;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ajax
   send ids to server and get result from server
   send result to applet
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;**/
  //alert(idsString);
  retrieveURL(url+idsString);
  multiApdu = req.responseText.split("&");
  for(var i=0;i<multiApdu.length;i++){
  //alert(i+"="+multiApdu[i].replace(" ",""));
   apduText = document.all.pcscCard.sendApdu(multiApdu[i].replace(" ",""));
   //alert("apduText="+apduText);
   result = result+apduText+"<br>";
   //alert("result="+result);
  }
  //apduText = document.all.pcscCard.sendApdu(req.responseText);
  //var apduText = document.all.pcscCard.sendApdu(req.responseText);
  //window.setTimeout("alert(result)",2000)
  
  //window.open("apduResult.jsp?result="+apduText);
  //window.location.href="apduResult.jsp?result="+apduText;
  var sendUrl = "apduResult.jsp?result="+result;
  window.location.href=sendUrl;
  //window.setTimeout("var sendUrl = 'apduResult.jsp?result='+apduText",5000)
  //document.getElementById("apduResult").innerHTML = req.responseText;
  }
  
  function getIds(){
   var boxes = document.getElementsByName("ids");
         var selectedIds = new Array();
         var idsString="";
         var j = 0;
      for (var i = 0; i < boxes.length; i++)
         {
          if (boxes[i].checked)
          {
           //alert(boxes[i].value);
              selectedIds[j] = boxes[i].value;
           //   alert("boxes[i].value="+boxes[i].value);
              j=j+1;
              /**
              idsString = idsString+selectedIds[j].value;
              if(i!=boxes.length-1){
               idsString = idsString + ","
              }
              **/
          }
      }
      //alert("selectedIds="+selectedIds);
      for ( var k = 0; k < selectedIds.length; k++) {
    idsString = idsString+selectedIds[k].value;
    //alert("selectedIds[k].value="+selectedIds[k].value);
              if(k!=boxes.length-1){
               idsString = idsString + "|"
              }
   }
      
      return selectedIds;
  }
  function retrieveURL(url) {
  if (window.XMLHttpRequest) { // Non-IE browsers
   req = new XMLHttpRequest();
   req.onreadystatechange = processStateChange;
   try {
    req.open("GET", url, true);
   } catch (e) {
    alert("´´½¨¶ÔÏóʧ°Ü");
   }
   req.send(null);
   } else if (window.ActiveXObject) { // IE
    req = new ActiveXObject("Microsoft.XMLHTTP");
    
    if (req) {
    req.onreadystatechange = processStateChange;
    req.open("post", url, false);
    req.send(null);
    
    }
   }
   //alert(req.responseText);
  }
  function processStateChange(){
   
   if (req.readyState == 4) { // Complete
    
    if (req.status ==200) { // OK response
    //alert(req.responseText);
     //apduText = document.all.pcscCard.sendApdu(req.responseText);
     //var apduText = document.all.pcscCard.sendApdu(req.responseText);
     //window.setTimeout("alert(apduText)",2000)
     //alert(apduText);
     //window.open("apduResult.jsp?result="+apduText);
     //window.location.href="apduResult.jsp?result="+apduText;
     //var sendUrl = "apduResult.jsp?result="+apduText;
     
     //window.setTimeout("var sendUrl = 'apduResult.jsp?result='+apduText",5000)
     //window.location.href=sendUrl;
     //window.setTimeOut("window.location.href=sendUrl",5000);
     //window.setTimeOut("",5000);
    }
    if (req.status !=200) { // OK response
     checkDiv();
     processStateChange();
    }
    
   }
   if (req.readyState < 4) { // Complete
    checkDiv();
    //alert("ÕýÔÚ¶ÁÈ¡");
   }
  }
  function checkDiv() {

            var progress_bar = document.getElementById("processing");
   //alert(progress_bar.style.visibility);
            if (progress_bar.style.visibility == "hidden") {
    progress_bar.style.visibility == "visible";
            }
            if (progress_bar.style.visibility == "visible") {
    progress_bar.style.visibility == "hidden";
            }
           
        }
</script>
</head>
<body>
<logic:present name="msg">
 <bean:write name="msg"/>
</logic:present>
<form method="post" name="appFileFrm" οnsubmit="changePage('')"  action="changePage.html">
<!--<applet alt="apdu"
archive="ocf.jar"
codebase="/FFTWeb/"
name="pcscCard" width="100"
height="100"
 code="com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory">
</applet>
--><jsp:plugin code="com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory"
 codebase="/FFTWeb/"
 type="applet"
 archive="ocf.jar"
 name="pcscCard"
 width="100"
 height=""></jsp:plugin>
<table width="100%">
<logic:present name="list">
 <tr bgcolor="#e4e4e4">
      <td align="center" width="80">
      <input name="allAppFile" type="button" id="allAppFile" value="全选" οnclick="checkList(this,'i')"></td>
      <td align="center">编号</td>
      <td align="center">标题</td>
      <td align="center">作者</td>
      <td align="center">创建时间</td>
      <td align="center">修改时间</td>
      <td align="center">修改</td>
      <td align="center">查看</td>
    </tr>
 <logic:iterate id="l" name="list">
 <tr>
  <td align="center"><input type="checkbox" name="ids" id="ids" value="<bean:write name="l" property="id"/>"></td>
        <td align="center"><bean:write name="l" property="id"/></td>
        <td align="center"><bean:write name="l" property="title"/></td>
        <td align="center"><bean:write name="l" property="author"/></td>
        <td align="center"><bean:write name="l" property="createtime"/></td>
    <td align="center"><bean:write name="l" property="updatetime"/></td>
<td align="center"><a href="findAppfile.html?id=<bean:write name="l" property="id"/>">修改</a></td>
      <td align="center"><a href="showAppfile.html?id=<bean:write name="l" property="id"/>">查看</a></td>
 </tr>
<tr><td colspan="8" bgcolor="#e4e4e4"></td></tr>
 </logic:iterate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr>
      <td align="center"><input type="button" οnclick="confirmDelete('您将删除这些文件,并且不可恢复,确认吗?','delete');" name="Submit" value="删除">
<input type="button" οnclick="return sendApdu('sendApdu.html?idsString=');" value="发送apdu指令">
      <input type="reset" name="Submit2" value="取消"></td>
    </tr>
  </table>
  <%@include file="../inc/changepage.jsp" %>
</logic:present>
</form>
</body>
</html>

AppfileAction.java

package appfile.action;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import pojo.AppFile;
import pojo.FileForm;
import util.TimeUtile;

import appfile.service.IAppfileService;

public class AppfileAction extends DispatchAction {
 private IAppfileService appFileServ=null;
 private String msg = "msg";
 public ActionForward saveAppfile(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  FileForm fForm = (FileForm)form;
  String title = request.getParameter("title");
  String author = request.getParameter("author");
  String description = request.getParameter("description");
  String createtime = new TimeUtile().getCurrentTimeToString();
  byte[] fileContent = fForm.getFilecontent().getFileData();
  AppFile appFile = new AppFile();
  appFile.setAuthor(author);
  appFile.setTitle(title);
  appFile.setCreatetime(createtime);
  appFile.setDescription(description);
  appFile.setContent(fileContent);
  String saveOk = appFileServ.uploadAppfile(appFile, "上传成功");
  request.setAttribute(msg, saveOk);
  return mapping.findForward("sucess");
 }
 
 public ActionForward updateAppfile(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  FileForm fForm = (FileForm)form;
  String id = request.getParameter("id");
  String title = request.getParameter("title");
  String author = request.getParameter("author");
  String description = request.getParameter("description");
  String createtime = request.getParameter("createtime");
  String updatetime = new TimeUtile().getCurrentTimeToString();
  byte[] fileContent = fForm.getFilecontent().getFileData();
  AppFile appFile = new AppFile();
  appFile.setId(Integer.parseInt(id));
  appFile.setCreatetime(createtime);
  appFile.setAuthor(author);
  appFile.setTitle(title);
  appFile.setUpdatetime(updatetime);
  appFile.setDescription(description);
  appFile.setContent(fileContent);
  String saveOk = appFileServ.updateAppfile(appFile, "修改成功");
  request.setAttribute("appFile", appFile);
  request.setAttribute(msg, saveOk);
  return mapping.findForward("sucess");
 }
 
 public ActionForward findAll(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  // TODO Auto-generated method stub
  return mapping.findForward("sucess");
 }
 
 public ActionForward deleteAppfile(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  
  return mapping.findForward("sucess");
 }
 
 public ActionForward findById(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  String id = request.getParameter("id");
  AppFile appFile = appFileServ.findById(Integer.parseInt(id));
  request.setAttribute("appFile", appFile);
  return mapping.findForward("sucess");
 }
 
 public ActionForward sendApdu(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  //String[] apduIds = request.getParameterValues("ids");
  String idsString = request.getParameter("idsString");
  String[] apduIds = idsString.split(",");
  String apduResult = appFileServ.sendApdu(apduIds);
  PrintWriter out = response.getWriter();
  out.write(apduResult.replace(" ", ""));
  System.out.println("apduResult="+apduResult);
  //out.print(apduResult.replace(" ", ""));
  return null;
 }
 
 public ActionForward redirectAddAppfile(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  // TODO Auto-generated method stub
  return mapping.findForward("sucess");
 }
 
 public IAppfileService getAppFileServ() {
  return appFileServ;
 }
 public void setAppFileServ(IAppfileService appFileServ) {
  this.appFileServ = appFileServ;
 }
 @Override
 protected String getMethodName(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response,
   String parameter) throws Exception {
  // TODO Auto-generated method stub
  return parameter;
 }
}
AppfileDao.java

package appfile.dao;

import java.util.List;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import pojo.AppFile;

public class AppfileDao extends HibernateDaoSupport implements IAppfileDao {

 @Override
 public String deleteAppfile(String[] ids) {
  // TODO Auto-generated method stub
  return null;
 }

 @Override
 public List findAll() {
  // TODO Auto-generated method stub
  return null;
 }

 @Override
 public AppFile findById(int id) {
  Session session = getSession(true);
  AppFile appFile = (AppFile)session.get(AppFile.class, id);
  session.flush();
  session.clear();
  return appFile;
 }

 @Override
 public String sendApdu(String[] ids) {
  StringBuffer sb = new StringBuffer();
  Session session = getSession(true);
  for (int i = 0; i < ids.length; i++) {
   AppFile appFile = (AppFile)session.get(AppFile.class, Integer.parseInt(ids[i]));
   sb.append(new String(appFile.getContent()));
   if(i!=ids.length-1){
    sb.append("&");
   }
  }
  session.flush();
  session.clear();
  return sb.toString();
 }

 @Override
 public String updateAppfile(AppFile appFile, String update) {
  try {
   getHibernateTemplate().update(appFile);
   getHibernateTemplate().flush();
  } catch (Exception e) {
   update = e.getMessage();
  }
  
  return update;
 }

 @Override
 public String uploadAppfile(AppFile appFile, String uploadOk) {
  try {
   getHibernateTemplate().save(appFile);
   getHibernateTemplate().flush();
  } catch (Exception e) {
   uploadOk = e.getMessage();
  }
  
  return uploadOk;
 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值