请教大家拉!!!!

解决方案 »

  1.   

    文件上传没什么好说的啊   界面上设置一个 input type=file的  指定文件 然后 用formfile接收 action获取到了 写入磁盘 就ok了啊  
      

  2.   

    想在jsp中嵌套纯java代码,可以通过底层的二进制流来取得上传的文件内容并将该文件放到web应用所在的路径,从而实现上传。如下列代码——》
    a.html->-----------------------------------------------------------------------------
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title> fileUpload </title>
    <meta name="author" content="Yeeku.H.Lee" />
    <meta name="website" content="http://www.crazyit.org" />
    <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
    </head>
    <body>
    <form enctype="multipart/form-data" 
    method="post" action="b.jsp">
    上传文件: <input type="file" name="file" /><br>  
    请求参数 <input type="text" name="wawa" /><br>
    <input type="submit" value="提交" />
    </form>
    </body>
    </html>
    b.jsp->------------------------------------------------------------------<%@ page contentType="text/html;charset=GBK" %>
    <%@ page import="java.io.*"%>
    <%
    //取得HttpServletRequest的InputStream输入流
    InputStream is = request.getInputStream();
    //以InputStream输入流为基础,建立一个BufferedReader对象
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String buffer = null;
    //循环读取请求内容的每一行内容
    while( (buffer = br.readLine()) != null)
    {

    if(buffer.endsWith("--") && buffer
    .startsWith("-----------------------------"))
    {
    break;
    }

    if(buffer.startsWith("-----------------------------"))
    {

    if (br.readLine().indexOf("filename") > 1)
    {
    //跳过两行,开始处理上传的文件内容
    br.readLine();
    br.readLine();
    //以系统时间为文件名,创建一个新文件
    File file = new File(request.getRealPath("/") 
    + System.currentTimeMillis());
    //创建一个文件输出流
    PrintStream ps = new PrintStream(new FileOutputStream(file));
    String content = null;
    //接着开始读取文件内容
    while( (content = br.readLine()) != null)
    {

    if(content.startsWith("-----------------------------"))
    {

    break;
    }
    //将读到的内容输出到文件中
    ps.println(content);
    }

    ps.flush();
    ps.close();
    }
    }
    }
    br.close();
    %>