I am trying to upload a photo using UploadBean. But I am getting unexpected error.
Here's my code:
<html>
<%@ page language="java" import="javazoom.upload.*,java.util.*" %>
<%@ page errorPage="ExceptionHandler.jsp" %>
<jsp:useBean id="upBean" scope="application" class="javazoom.upload.UploadBean" >
<%
Properties props = new Properties();
// Modify info below to fit to your database settings.
props.put("user","db2inst1");
props.put("password","9231827765");
upBean.setDatabasestore("com.ibm.db2.jcc.DB2Driver",
"jdbc:db2://localhost:50000/DB2_TEST", props);
// If you have get a JDBC Connection from a javax.sql.DataSource
// Then use upBean.setDatabasestore(YourConnection);
// Also, uncomment and modify variables below if you need to map to your own database schema.
UploadBean.SQLUPLOADTABLE = "PHOTO";
UploadBean.SQLUPLOADID = "UPLOADID";
UploadBean.SQLUPLOADFILENAME = "FILENAME";
UploadBean.SQLUPLOADFILE = "BINARYFILE";
// Note that if you need to modify SQL request then see UploadBean
// add-ons section to plug a custom DBStore implementation (BLOB, ...).
%>
</jsp:useBean>
<jsp:setProperty name="upBean" property="overwrite" value="true" />
<head>
<title>Samples : Database Upload</title>
<style TYPE="text/css">
<!--
.style1 {
font-size: 12px;
font-family: Verdana;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<ul class="style1">
<%
if (MultipartFormDataRequest.isMultipartFormData(request))
{
// Uses MultipartFormDataRequest to parse the HTTP request.
MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
String todo = null;
if (mrequest != null) todo = mrequest.getParameter("todo");
if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
{
Hashtable files = mrequest.getFiles();
if ( (files != null) && (!files.isEmpty()) )
{
UploadFile file = (UploadFile) files.get("uploadfile");
if (file != null) out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
// Store uploaded files in database now. Third parameter allows to pass options Map.
HashMap options = null;
// Sample advanced options.
//options = new HashMap();
//options.put("dbstore.uploadid","id."+System.currentTimeMillis());
//options.put("dbstore.filesize","enabled");
//options.put("dbstore.filetype","enabled");
//options.put("dbstore.customcolumn.created_date",new Date());
upBean.store(mrequest, "uploadfile", options);
// int lastid = ((DefaultDBStore)upBean.getDatabasestoreimplementation()).getLastId();
}
else
{
out.println("<li>No uploaded files");
}
}
else out.println("<BR> todo="+todo);
}
Vector history = upBean.getHistory();
int amount = 0;
if (history != null) amount = history.size();
%>
<br><i>(Uploaded files : <%= amount %>)</i>
</ul>
<form method="post" action="dbupload.jsp" name="upform" enctype="multipart/form-data">
<table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
<tr>
<td align="left"><b>Select
a file to upload :</b></td>
</tr>
<tr>
<td align="left">
<input type="file" name="uploadfile" size="50">
</td>
</tr>
<tr>
<td align="left">
<input type="hidden" name="todo" value="upload">
<input type="submit" name="Submit" value="Upload">
<input type="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
<br>
<br>
<table border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td bgcolor="#666666">
<table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="style1">
<tr>
<td bgcolor="#FFFFFF"><b><font color="#0000FF">
HTML tags used in this form :</font></b></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> <<b>form</b>
<b>method</b>="<b><font color="#FF0000">post</font></b>"
<b>action</b>="<b><font color="#FF0000">DatabaseUpload.jsp</font></b>"
name="upload" <b>enctype</b>="<b><font color="#FF0000">multipart/form-data</font></b>"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> <<b>input</b>
<b>type</b>="<b><font color="#FF0000">file</font></b>"
<b>name</b>="<font color="#FF0000"><b>uploadfile</b></font>"
size="50"></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"><font size="-1" face="Courier New, Courier, mono">Copyright
© <a href="http://www.javazoom.net" target="_blank">JavaZOOM</a> 1999-2006</font></p>
</form>
</body>
</html>
And my exception is :
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /test/dbupload.jsp(5,0) The value for the useBean class attribute javazoom.upload.UploadBean is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1220)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Generator.generate(Generator.java:3417)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:231)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
note The full stack trace of the root cause is available in the Apache Geronimo (Embedded Tomcat/@VERSION@) logs.
Apache Geronimo (Embedded Tomcat/@VERSION@)
My Server is : IBM WebSphere Application Server Community Edition ( Apache Geronimo 2.1 )
My Database is : IBM DB2 Express C 9.7.2
Can you please help me ?
[Updated on: Fri, 05 November 2010 07:23]
Report message to a moderator