uploading a file using jsp and com.oreilly.servlet lib package

Sorry to bother you but I need your help folks

I am developing an application to pick up files from a database and sent to a specified location on a different system.

I am presently trying to run this code,I have placed this lib package from oreilly which is supposed to encapsulate the usage of file uploads,which is a jar file called cos.jar into C:\Program Files\Java\jdk1.5.0_03\jre\lib\ext folder .I have a jsp page that calls the bean which does the upload and implement the classes in the oreilly package.I am using tomcat 5

[b]the jsp page that acts as the user interface

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Please Choose The File</title>

</head>

<body bgcolor="#ffffff">

<table border="0"><tr>

<form action="Upload.jsp" method="post"

enctype="multipart/form-data">

<td valign="top"><strong>Please choose your document:</strong>

</td>

<td> <input type="file" name="file1">

</td></tr>

<tr><td><input type="submit" value="Upload File"></td></tr>

</form>

</table>

</body>

</html>

this is the jsp page that calls the bean

<jsp:useBean id="uploader" class="com.UploadBean" />

<jsp:setProperty name="uploader" property="dir" value="<%=application.getInitParameter(\"save-dir\")%>" />

<jsp:setProperty name="uploader" property= "req" value="${pageContext.request}" />

<html>

<head><title>file uploads</title></head>

<body>

<h2>Here is information about the uploaded files</h2>

<jsp:getProperty name="uploader" property="uploadedFiles" />

</body>

</html>

[b]this is the bean class

package com;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.ServletRequest;

import com.oreilly.servlet.MultipartRequest;

import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;

import javax.servlet.*;

public class UploadBean {

private String webTempPath;

private HttpServletRequest req;

private String dir;

// private ServletRequest request;

public UploadBean( ) {}

public void setDir(String dirName) {

if (dirName == null || dirName.equals(""))

throw new IllegalArgumentException("invalid value passed to " + getClass( ).getName( )+".setDir");

//webTempPath = dirName;

dir = dirName;

}

/* public String getDir()

{

return webTempPath;

} */

public void setReq(ServletRequest request) {

if (request != null && request instanceof HttpServletRequest)

{

req = (HttpServletRequest) request;

} else {

throw new IllegalArgumentException("Invalid value passed to " + getClass( ).getName( )+".setReq");

}

}

public String getUploadedFiles( ) throws java.io.IOException{

//file limit size of 5 MB

MultipartRequest mpr = new MultipartRequest(req,dir,5 * 1024 * 1024,new DefaultFileRenamePolicy( ));

Enumeration enume = mpr.getFileNames( );

StringBuffer buff = new StringBuffer("");

for (int i = 1; enume.hasMoreElements( );i++){

buff.append("The name of uploaded file ").append(i).append(" is: ").append(mpr.getFilesystemName((String)enume.nextElement( ))).append("

");

}//for

//return the String

return buff.toString( );

} // getUploadedFiles

}

On running the code I find this error messages

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax/servlet/ServletRequest

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)

org.apache.jsp.jsp.Upload_jsp._jspService(org.apache.jsp.jsp.Upload_jsp:73)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.NoClassDefFoundError: javax/servlet/ServletRequest

com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:222)

com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:151)

com.UploadBean.getUploadedFiles(UploadBean.java:49)

org.apache.jsp.jsp.Upload_jsp._jspService(org.apache.jsp.jsp.Upload_jsp:63)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.

--

Apache Tomcat/5.5.9

tanks

[5752 byte] By [olicksa] at [2007-10-2 6:58:25]
# 1

Hi,

Looks like you are missing a file from the classpath. Make sure servlet.jar is available in your classpath. Ordinarily files in <tomcat_home>/lib directory should be added automatically. You need to check why it hasn't been added in your case. A good place to start would be the bat files in the bin directory viz startup.bat, catalina.bat etc.

cheers,

vidyut

vidyuta at 2007-7-16 20:27:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...