易截截图软件、单文件、免安装、纯绿色、仅160KB

关于java的http协议文件上传实用例题一

关于java的http协议文件上传实用例题一
(2006-07-25 16:43:56)
转载

 

分类:
java
关于java的http协议上传:(简单实用而且健壮;速度快)
此方法比apache的文件上传包(uploadfile1.1:就文件上传功能而言)要强多了
1.只需要一个MultipartRequest.java基本文件就行。
2.前台html的基本格式
<html><body><form enctype="multipart/form-data"
method="post">
<input type="file" name="path"
size="38" />
<input type="text"
name="res_name" size="38" />
</body></html>
3.后台调用此文件方法如下:
req是HttpServletRequest类.
try {
   if
(req.getMethod().equals("POST") &&
MultipartRequest.isMultipart(req)) {
    req = new
MultipartRequest(req, userId);//userId登陆用户标识
   
//得到上传文件
    File
upFile = ((MultipartRequest) req).getFile("path");
//得到上传文件名
    String
fileName = ((MultipartRequest) req).getFileName(upFile);
//得到上传http的值
  
req.getParameter("res_name");
//把上传文件存放到c:/temp目录下名为123.jpg的文件
   saveAs(upFile,
"c:/temp/123.jpg");
finally {
   if (req instanceof
MultipartRequest) {
   
//清除上传的临时文件
     
((MultipartRequest) req).deleteTemporaryFile();
   }
//把上传文件存放到指定的目录下文件名
private void saveAs(File upFile, String filePath) throws
IOException {
  FileInputStream fis =
null;
  FileOutputStream fos =
null;
  try {
   fis = new
FileInputStream(upFile);
   int len =
fis.available();
   byte[] by =
new byte[len];
   fis.read(by);
   fos = new
FileOutputStream(filePath);
   fos.write(by);
  }
  finally {
  &n


相关文档:

Java的单例模式例子

1. 先写一个Singleton的class
package stone;
public class Singleton {
    private static Singleton instance;
    private Singleton() {}
    public static Singleton getInstance(){
        if(instance==null)
  &n ......

Java 中的位运算


移位运算符

    包括:
    “>> 右移”;“<< 左移”;“>>> 无符号右移”
例子:
-5>>3=-1
1111 1111 1111 1111 1111 1111 1111 1011
1111 1111 1111 1111 1111 1111 1111 1111
其结果与 Math.floor((double)- ......

Java两种异常模式

Java里有个很重要的特色是Exception ,也就是说允许程序产生例外状况。而在学Java 的时候,我们也只知道Exception 的写法,却未必真能了解不同种类的Exception 的区别。
首先,您应该知道的是Java 提供了两种Exception 的模式,一种是执行的时候所产生的Exception (Runtime Exception),另外一种则是受控制的Exception ......

JAVA最短路径代码

import java.util.LinkedList;
import java.util.List;
public class ShortestPaths {
     private static String showPath[] = { "", "", "", "", "", "" }; 
      
     & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号