dsoframe.ocx实现远程下载编辑后利用反射回传保存

阅读更多

1、加载页面index.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>



 
  
  My JSP 'index.jsp' starting page

  
 

 
     codeBase="dsoframer.ocx" #Version="2,3,0,0" id="Mydso" name="Mydso"
   width='1100' height='800' align=center hspace=0 vspace=0>
  

    

      onsubmit="return upload()">
      
      
      
      
     

<%--  --%>
<%--   --%>
<%--    --%>
<%--     
<%--      codeBase="dsoframer.ocx" #Version="2,3,0,0" id="Mydso"--%>
<%--      name="Mydso" width='100%' height='1000%' align=center hspace=0--%>
<%--      vspace=0>--%>
<%--     
--%>
<%--    --%>
<%--   
--%>
<%--   --%>
<%--    --%>
<%--     

<%--      onsubmit="return save()">--%>
<%--      --%>
<%--      --%>
<%--      --%>
<%--     --%>
<%--    --%>
<%--   
--%>
<%--  
--%>
 

2、处理页面uoload.jsp

<%@page
 import="com.jspsmart.upload.SmartUpload,org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest"%>
<%@ page language="java"
 import="java.util.*,java.io.*,java.lang.reflect.*,org.apache.commons.fileupload.*,org.apache.commons.fileupload.disk.*"
 pageEncoding="UTF-8"%>


 
  <%
   Class multi = request.getClass();
   Field personNameField = multi.getDeclaredField("multi");
   personNameField.setAccessible(true);
   JakartaMultiPartRequest partRequest = (JakartaMultiPartRequest) personNameField
     .get(request);

   Class fileClass = partRequest.getClass();
   Field uploadFiles = fileClass.getDeclaredField("files");
   uploadFiles.setAccessible(true);
   Map fileMap = (Map) uploadFiles.get(partRequest);

   System.out.println(fileMap);
   if (null != fileMap && !fileMap.isEmpty()) {
    List fileItem = (List)fileMap.get("FileData");

    for (DiskFileItem diskFile : fileItem) {
     DiskFileItem disk =  diskFile;
     File temp = new File("d:\\tewt.doc");
     disk.write(temp);
    }
   }
  %>
 

3、本地处理action

/**
 *
 */
package com.test.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class UploadAction extends ActionSupport {
 private File upload;
 private String uploadContentType;
 private String uploadFileName;

 public File getUpload() {
  return upload;
 }

 public void setUpload(File upload) {
  this.upload = upload;
 }

 public String getUploadContentType() {
  return uploadContentType;
 }

 public void setUploadContentType(String uploadContentType) {
  this.uploadContentType = uploadContentType;
 }

 public String getUploadFileName() {
  return uploadFileName;
 }

 public void setUploadFileName(String uploadFileName) {
  this.uploadFileName = uploadFileName;
 }

 public HttpServletResponse getResponse() {
  HttpServletResponse response = null;
  try {
   response = ServletActionContext.getResponse();
  } catch (RuntimeException e) {
  }
  return response;
 }

 public HttpServletRequest getRequest() {
  HttpServletRequest request = null;
  try {
   request = ServletActionContext.getRequest();
  } catch (RuntimeException e) {
  }
  return request;
 }

 @Override
 public String execute() throws Exception {

  Map map = ActionContext.getContext().getParameters();

  boolean isMultipart = ServletFileUpload
    .isMultipartContent(getRequest());
  if (isMultipart) {// type=multipart/form-data
   DiskFileItemFactory factory = new DiskFileItemFactory();
   ServletFileUpload upload = new ServletFileUpload(factory);
   upload.setFileSizeMax(1024 * 1024);// 设置上传文件的最大容量
   List items = upload.parseRequest(getRequest());// 取得表单全部数据

   for (FileItem item : items) {
    if (item.isFormField()) {// 如果不是文件类型
     // String name = item.getFieldName(); 表单中某个控件的名称
     // String value = item.getString(); 表单中某个控件的值
    } else {
     String filename = item.getName();
     File f = new File(filename); // 保存的文件
     item.write(f);// 保存文件
    }
   }
  } else {

  }
  HttpServletRequest request = getRequest();
  FileOutputStream fos = new FileOutputStream("d:\\"
    + getUploadFileName());
  FileInputStream fis = new FileInputStream(getUpload());
  byte[] buffer = new byte[1024];
  int len = 0;
  while ((len = fis.read(buffer)) > 0) {
   fos.write(buffer, 0, len);
  }
  fos.close();
  fis.close();
  return SUCCESS;
 }
}

  4、web.xml配置


 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 online office

 
  struts2
  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
 

 
  struts2
  /*
 

 
  index.jsp
 

    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">


 
 

   namespace="/">

  
   index.jsp
   success.jsp
  

 

 

  • java-windows服务.rar (39.6 KB)
  • 下载次数: 17
  • 捕获.rar (20.5 KB)
  • 下载次数: 9

你可能感兴趣的:(dsoframe.ocx实现远程下载编辑后利用反射回传保存)