Re: upload file error, using com.oreilly.servlet.MultipartRequest 843841 May 16, 2003 10:49 PM ( in response to 843841 ) try putting the jar files in: C: Tomcat4 shared lib It's been a while since I did the install but I seem to remember this same issue. Also, it makes them available to all your web apps in there so that's nice for development.
Hello I�ve a form with a input type file and i want to send that file to the server so that i can read it and treated it. The code for this is '<form enctype='multipart/form-data' method='post' action='ver.jsp'> <input type='file' name='ficheiro'> <input type='submit' value='upload'> </form>' I saw the MultipartRequest class but i don�t know how to use. Can anyone help me. I am really desperate!!! Thanks Claudia
Ranch Hand
posted 18 years ago
Which MultipartRequest class? It's not part of the JDK, so you are probably referring to a package like com.oreilly.servlet www.servlets.com/cos This package is very easy to use. Just download the cos.jar file, add it to your CLASSPATH (for compiling), make sure it's also somewhere that your servlet runner can pick it up (Tomcat 3.x takes things from CLASSPATH, Tomcat 4.x uses CATALINA_HOME/common/lib), and the code is something like:
Greenhorn
posted 18 years ago
/* convert thie programm to JSP */ /* upload-FileUpload.java NOTE: This file is a generated file. Do not modify it by hand! */ package upload; // custom imports for FileUpload // add your custom import statements here import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import com.oreilly.servlet.MultipartRequest; import java.util.*; public class FileUpload extends javax.servlet.http.HttpServlet { protected boolean create() throws java.lang.Exception { return true; } public FileUpload() { // Constructor. } private void unhandledEvent( String listenerName, String methodName, java.lang.Object event ) { } /** * destroy Method */ public void destroy() { super.destroy(); // TODO: implement } /** * doGet Method */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType( 'text/html' ); PrintWriter out = response.getWriter(); out.println('<HTML>'); out.println('<HEAD><TITLE>FileUpload</TITLE></HEAD>'); out.println('<BODY>'); out.println('<H1>FileUpload</H1>'); out.println('Hello World!'); out.println('<P>Default Implementation From PowerJ</P>'); out.println('</BODY></HTML>'); // TODO: implement } /** * doPost Method */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); try{ response.setContentType('text/html'); out.println('<HTML>'); out.println('<head><Title>Decoded Uploaded File</title><head>'); out.println('<body>'); out.println('<H1>UploadFile</h1>'); // path must be absolute to upload dir // This is the decoder class that extracts the parameters and transfer file // request argument = Http input stream // c:tempupload = directory to save file // 15*1024*1024 = 15mb max size file MultipartRequest multi = new MultipartRequest(request, 'c:tempupload',15*1024*1024); // Lists form parameters out.println('Params:'); Enumeration params = multi.getParameterNames(); out.println('<pre>'); while (params.hasMoreElements()) { String name = (String)params.nextElement(); String value = multi.getParameter(name); out.println(name + ' = ' + value); } out.println('</pre>'); // Show details of uploaded file out.println('Files:'); Enumeration files = multi.getFileNames(); out.println('<pre>'); while (files.hasMoreElements()) { String name = (String)files.nextElement(); String filename = multi.getFilesystemName(name); String type = multi.getContentType(name); File f = multi.getFile(name); out.println('name: ' + name); out.println('filename: ' + filename); out.println('type: ' + type); if (f != null) { out.println('f.toString(): ' + f.toString()); out.println('f.getName(): ' + f.getName()); out.println('f.exists(): ' + f.exists()); out.println('f.length(): ' + f.length()); out.println(); } out.println('</pre>'); } }catch (Exception e){ out.println('<pre>'); e.printStackTrace(out); out.println('</pre>'); } out.println('</body></html>'); } /** * init Method */ public void init(ServletConfig config) throws ServletException { super.init(config); // TODO: implement } /**************************************** * data members ****************************************/ // add your data members here }
Ranch Hand
posted 19 years ago
Hi all, I am new to servlets& trying to write a mailserver pgm. in which I am using some methods from com.oreilly.servlet package. I downloaded it and stored in c:tomcat directory. The pgm. gives compilation error,'can't resolve symbol' for those method names. I am using jdk1.3 & Tomcat3.1. How can I successfully import com.oreilly.servlet.* package? Could someone please help? Thanks in advance. -sharon
Author and all-around good cowpoke
posted 19 years ago
I'm assuming you got a .jar file containing the com.oreilly.servlet classes. You must make this jar file visible to Tomcat by putting it in Tomcat/lib with the other toolkit libraries. Bill