Hi,
I have been trying to work on writing the servlet that uploads a
file with no luck. Particularly, I'm having problem using the
ENCTYPE=multipart/form-data attribute in the FORM tag. When the client
request is submitted with the filename, Netscape gives me an error
message. I don't get any error message when I don't use anything for the
ENCTYPE attribute. FYI I have the following environment:
Netscape Navigator 4.5 as the browser on a Win95 client PC
JSDK2.1 as the servlet server on a Unix server
This is the error message I get when I push the upload button:
A network error occurred while Netscape was receiving data.
(Netscape error: Connection reset by peer)
Try connecting again.
The following is the source code I'm using:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.MultipartRequest;
public class UploadTest extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
.... code same as Jason Hunter's uploadTest's POST method.
}
/*************** BEIGN doGet METHOD *********************/
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws IOException, ServletException
{
HttpSession session = request.getSession(true);
TargetBin targetbin = (TargetBin)session.getValue(session.getId());
//if the user has no TargetBin, then create one
if(targetbin == null)
{
targetbin = new TargetBin();
session.putValue(session.getId(), targetbin);
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML><HEAD><TITLE>Import File Prompt
Screen</TITLE></HEAD>");
out.println("<BODY BGCOLOR=\"#9FB9D2\" TEXT=\"000000\" LINK=\"0000FF\"
VLINK=\"0000FF\">");
out.println("<FORM ACTION=\"/servlet/UploadTest\"
ENCTYPE=\"multipart/form-data\" method=\"POST\">");
out.println("<CENTER>Select File to Import: <INPUT TYPE=\"FILE\"
NAME=\"FileName:\"><BR></CENTER>");
out.println("<CENTER><INPUT TYPE=\"SUBMIT\"> ");
out.println("<INPUT TYPE=\"BUTTON\" VALUE=\"Cancel\"
onClick=\"history.go(-1)\"> </CENTER>");
out.println("</FORM></BODY></HTML>");
out.close();
}
}
Desparately need some help on this.... :(
~Tariq~
begin:vcard
n:Islam;Tariq
tel;fax:(703) 908-4344
tel;work:(703) 908-4461
x-mozilla-html:FALSE
url:www.bah.com
org:Booz Allen & Hamilton;Defense
version:2.1
email;internet:[EMAIL PROTECTED]
title:Senior Consultant
adr;quoted-printable:;;4301 N. Fairfax Drive=0D=0ASuite 200;Arlington;VA;22203;USA
fn:Tariq Islam
end:vcard