Advertisement

[java] A "should be" simple question

Started by March 30, 2001 08:37 AM
0 comments, last by Smoo 23 years, 10 months ago
Ok, first off this is not a gaming question so don't start whining about it. As specified in the subject this should be a simple question. What I want to do is a simple upload program in HTML. Creating it is no problem. I link the <form ACTION> tag to a servlet which should "in theory" take the <input TYPE="FILE"> and upload the file to the server. Normally I would use a FileInputStream to get the url (the browse could have been like C:\log.txt). Obviously this is useless because it would search on the server's own machine so I'm attempting to use ServletInputStream, however this is still not working because I don't know how to link the ServletInputStream to the <input TYPE> String file; String fileContents = null; ArrayList al; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String urlStr = request.getParameter("fileUploader"); al = null; al = new ArrayList(); try { // ---------------------- Read the file from HD ----------------------------- //FileInputStream in = new FileInputStream(urlStr); ServletInputStream sis; sis = request.getInputStream(); boolean eof = false; int i=0; while (!eof) { int x = sis.read(); Integer y = new Integer(x); al.add(y); if (x == -1) eof = true; i++; } //in.close(); sis.close(); // --------------------- Write the file to the server (hopefully) ------------------------ StringTokenizer st = new StringTokenizer(urlStr, "\\"); while (st.hasMoreTokens()) file = st.nextToken(); FileOutputStream out = new FileOutputStream(file); for (int a=0; a< al.size();a++) { Integer x = (Integer)al.get(a); out.write(x.intValue()); } out.flush(); out.close(); } catch (Exception e) { e.printStackTrace();} } If you guys have some suggestions I would greatly appreciate it. I want to do this in java, jsp, java-script or some java-related solution. I'm not looking for an asp, php, cgi, one of those solutions. If I were, i'd have gone elsewhere to look. Thanks, Smoo Edited by - Smoo on March 30, 2001 10:07:20 AM
If this was a game question then I''d be able to answer your question, but since it''s not, I''m going to have to refuse to tell you that the best place to look for the answer is the following URL:

http://www.servlets.com/resources/com.oreilly.servlet/index.html

(download the multipart request, which is what a file upload is).

This topic is closed to new replies.

Advertisement