ClsMultipartProcess.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:4k
源码类别:
OA系统
开发平台:
Java
- package com.gforce.currency.clsupload;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.io.*;
- import java.util.*;
- /**
- * <p>Title: 吉力科技办公自动化系统</p>
- * <p>Description: 吉力科技办公自动化系统</p>
- * <p>Copyright: 版权所有 2003 (c) 西安吉力科技发展有限公司 Copyright (c) 2003 GForce Sceince & Technology</p>
- * <p>Company: 西安吉力科技发展有限公司 (GForce Sceince & Technology)</p>
- * @author 马登军
- * @version 1.0
- */
- public class ClsMultipartProcess
- {
- private static final String disposition="Content-Disposition: form-data; name="";
- private String boundary=null;
- private String formData=null;
- private int formLength=0;
- public ClsMultipartProcess(HttpServletRequest request)
- {
- try
- {
- DataInputStream in=new DataInputStream(request.getInputStream());
- String contentType=request.getContentType();
- formLength=request.getContentLength();
- if (formLength>0)
- {
- boundary=contentType.substring(contentType.lastIndexOf("=")+1,
- contentType.length());
- byte buffer[]=new byte[formLength];
- int readedNumber=0;
- int totalReadedNumber=0;
- while(totalReadedNumber<formLength)
- {
- readedNumber=in.read(buffer, totalReadedNumber,
- formLength-totalReadedNumber);
- totalReadedNumber+=readedNumber;
- }
- formData=new String(buffer, "ISO8859-1");
- buffer=null;
- }
- }
- catch(IOException ex)
- {
- ex.printStackTrace();
- }
- }
- public String getValue(String controlName)
- {
- String searchStr=disposition+controlName+""";
- String value=null;
- if (formLength>0)
- {
- int startPoint=formData.indexOf(searchStr);
- if (startPoint!=-1)
- {
- startPoint=formData.indexOf("n", startPoint)+1;
- startPoint=formData.indexOf("n", startPoint)+1;
- int endPoint=formData.indexOf(boundary, startPoint)-4;
- value=formData.substring(startPoint, endPoint);
- }
- }
- return value;
- }
- public String getFileName(String controlName)
- {
- String searchStr=disposition+controlName+""; filename="";
- String fileName=null;
- if (formLength>0)
- {
- int startPoint=formData.indexOf(searchStr);
- int endPoint=formData.indexOf("n", startPoint);
- if (startPoint!=-1)
- {
- startPoint=startPoint+searchStr.length();
- fileName=formData.substring(startPoint, endPoint-2);
- int pos=fileName.lastIndexOf("\");
- if (pos!=-1)
- {
- fileName=fileName.substring(pos+1);
- }
- if (fileName!=null)
- {
- try
- {
- fileName=new String(fileName.getBytes("ISO8859-1"));
- }
- catch(UnsupportedEncodingException ex)
- {
- ex.printStackTrace();
- }
- }
- }
- }
- return fileName;
- }
- public String getFileContent(String controlName)
- {
- String searchStr=disposition+controlName+""; filename="";
- String fileContent=null;
- if (formLength>0)
- {
- int startPoint=formData.indexOf(searchStr);
- if (startPoint!=-1)
- {
- startPoint=formData.indexOf("n", startPoint)+1;
- startPoint=formData.indexOf("n", startPoint)+1;
- startPoint=formData.indexOf("n", startPoint)+1;
- int endPoint=formData.indexOf(boundary, startPoint)-4;
- fileContent=formData.substring(startPoint, endPoint);
- }
- }
- return fileContent;
- }
- }