Dear all:
        I want to upload one file to the server from client,but i can't make
it work,
can anybody tell me what's wrong with it.

the HTML form is :  upload.html
<html><body>
<form method="POST" enctype="multipart/form-data" action="upload.jsp" >
File 1:<input type="file" name="file1">
<br>
<input type="submit" value="Upload!">
</form></body></html>

the Jsp code is :  upload.jsp
<html>
<head>
<title> test for file input</title>
<%@ page language="java" import = "java.lang.*" %>
<%@ page import = "java.io.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.sql.* " %>
<%@ page contentType = "text/html; charset = gb2312" %>
</head>
<body>
<%
   String req = request.getParameter("file1");
   File filename = new File(req);

    if (req != null)
    {
        int s;
        DataInputStream rdata=new DataInputStream(new
FileInputStream(filename));
        DataOutputStream wdata = new DataOutputStream(new
BufferedOutputStream(new FileOutputStream("/work/filename" )));
        while ( (s = rdata.read()) != -1)
               wdata.writeByte(s);
       rdata.close();
       wdata.close();
   }
   else out.println("error!");
%>
</body>
</html>

thanks in advance !
elteon

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to