Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

uploading a photo  RSS feed

 
victor bwalya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai hav been trying to upload a photo but am getting an error PLIZ HELP.



this is the error message am getting

[ The value for the useBean class attribute javazoom.upload.UploadBean is invalid.]

andthis is the CODE




<html>
<body bgcolor="#333333">

<%@ page language="java" import="javazoom.upload.*,java.util.*,java.io.*" %>
<%@ page errorPage="ExceptionHandler.jsp" %>

<% String directory = "c:/Missing Person"; %>
<% String tmpdirectory = "c:/Missing Person/tmp"; %>
<% boolean createsubfolders = true; %>
<% boolean allowresume = true; %>
<% boolean allowoverwrite = true; %>
<% String encoding = "ISO-8859-1"; %>
<% boolean keepalive = false; %>

<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
<jsp:setProperty name="upBean" property="folderstore" value="<%= directory %>" />
<jsp:setProperty name="upBean" property="parser" value="<%= MultipartFormDataRequest.CFUPARSER %>"/>
<jsp:setProperty name="upBean" property="parsertmpdir" value="<%= tmpdirectory %>"/>
<jsp:setProperty name="upBean" property="filesizelimit" value="8589934592"/>
<jsp:setProperty name="upBean" property="overwrite" value="<%= allowoverwrite %>"/>
<jsp:setProperty name="upBean" property="dump" value="true"/>
</jsp:useBean>

<%
//request.setCharacterEncoding(encoding);
//response.setContentType("text/html; charset="+encoding);
String method = request.getMethod();
// Head processing to support resume and overwrite features.
if (method.equalsIgnoreCase("head"))
{
String filename = request.getHeader("relativefilename");
if (filename == null) filename = request.getHeader("filename");
if (filename!=null)
{
if (keepalive == false) response.setHeader("Connection","close");
String account = request.getHeader("account");
if (account == null) account="";
else if (!account.startsWith("/")) account = "/"+account;
File fhead = new File(directory+account+"/"+filename);
if (fhead.exists())
{
response.setHeader("size", String.valueOf(fhead.length()));
String checksum = request.getHeader("checksum");
if ((checksum != null) && (checksum.equalsIgnoreCase("crc")))
{
long crc = upBean.computeCRC32(fhead,-1);
if (crc != -1) response.setHeader("checksum", String.valueOf(crc));
}
else if ((checksum != null) && (checksum.equalsIgnoreCase("md5")))
{
String md5 = upBean.hexDump(upBean.computeMD5(fhead,-1)).toLowerCase();
if ((md5 != null) && (!md5.equals(""))) response.setHeader("checksum", md5);
}
}
else response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
%>
<html>
<head>
<title>Samples : Large Upload + jClientUpload Applet support</title>
<style TYPE="text/css">
<!--
.style1 {
font-size: 12px;
font-family: Verdana;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=<%= encoding %>">




<script language="Javascript"><!--

function doClean()
{
document.upload.todo.value="cleanstore";
document.upload.submit();
}
//--></script>
</head>
<body>
<ul class="style1">
<%
if (MultipartFormDataRequest.isMultipartFormData(request))
{
// Parse multipart HTTP POST request.
MultipartFormDataRequest mrequest = null;
try
{
mrequest = new MultipartFormDataRequest(request,null,-1,MultipartFormDataRequest.CFUPARSER,encoding,allowresume);
} catch (Exception e)
{
// Cancel current upload (e.g. Stop transfer)
// Only if allowresume = false
}
String todo = null;
if (mrequest != null) todo = mrequest.getParameter("todo");
if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
{
String account = mrequest.getParameter("account");
if (account == null) account="";
else if (!account.startsWith("/")) account = "/"+account;
upBean.setFolderstore(directory+account);
Hashtable files = mrequest.getFiles();
if ( (files != null) && (!files.isEmpty()) )
{
UploadFile file = (UploadFile) files.get("uploadfile");
if (file != null) out.println("<b> Successfully Uploaded the Missing Person's photo : "+file.getFileName());
// Folders and subfolders creation support.
String relative = mrequest.getParameter("relativefilename");
if ((createsubfolders == true) && (relative != null))
{
int inda=relative.length();
int indb=file.getFileName().length();
if (inda > indb)
{
String subfolder = relative.substring(0,(inda-indb)-1);
subfolder = subfolder.replace('\\','/').replace('/',java.io.File.separatorChar);
upBean.setFolderstore(directory+account+java.io.File.separator+subfolder);
}
}
if (keepalive == false) response.setHeader("Connection","close");
// Chunks recomposion support.
String chunkidStr = mrequest.getParameter("chunkid");
String chunkamountStr = mrequest.getParameter("chunkamount");
String chunkbaseStr = mrequest.getParameter("chunkbase");
if ((chunkidStr != null) && (chunkamountStr != null) && (chunkbaseStr != null))
{
// Always overwrite chunks.
upBean.setOverwrite(true);
upBean.store(mrequest, "uploadfile");
upBean.setOverwrite(allowoverwrite);
int chunkid = Integer.parseInt(chunkidStr);
int chunkamount = Integer.parseInt(chunkamountStr);
if (chunkid == chunkamount)
{
// recompose file.
String fname = upBean.getFolderstore()+java.io.File.separator+chunkbaseStr;
File fread = new File(fname);
if (fread.canRead() && (upBean.getOverwrite()==false)) fname = upBean.loadOverwriteFilter().process(fname);
FileOutputStream fout = new FileOutputStream(fname);
byte[] buffer = new byte[4096];
for (int c=1;c<=chunkamount;c++)
{
File filein = new File(upBean.getFolderstore()+java.io.File.separator+chunkbaseStr+"."+c);
FileInputStream fin = new FileInputStream(filein);
int read = -1;
while ((read = fin.read(buffer)) > 0) fout.write(buffer,0,read);
fin.close();
filein.delete();
}
fout.close();
}
}
else upBean.store(mrequest, "uploadfile");
upBean.setFolderstore(directory+account);
}
else
{
String emptydirectory = mrequest.getParameter("emptydirectory");
if ((emptydirectory != null) && (!emptydirectory.equals("")))
{
File dir = new File(directory+account+"/"+emptydirectory);
dir.mkdirs();
}
out.println("<li>No uploaded files");
}
}

else if ( (todo != null) && (todo.equalsIgnoreCase("cleanstore")) )
{
upBean.resetStore();
out.println("<BR>Store cleaned");
}

}
%>
</ul>
<form method="post" action="umLargeUpload.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="hidden" name="todo" value="upload">
<input type="file" name="uploadfile" size="50">
</td>
</tr>
<tr>
<td align="left">
<input type="submit" name="Submit" value="Upload">
<input type="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of putting all of that Java code into a JSP, you would be better off putting it into a servlet. Much easier to work with, much less amateurish too. You don't need all of that JSP baggage to upload a file.
 
victor bwalya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so how do i do that,,i still cnt manage to upload,its still givin me the same error!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is impossible. If you have moved the code to a servlet, there's no useBean tag to generate the error.

Putting Java code in a JSP is an anti-pattern that has been discredited for 10 years now. Put the code into a servlet where it belongs.
 
victor bwalya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont know were doing it wrong,,can you help me put the code into a servlet,,,PLEASE!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you ever written a servlet? If not, there are plenty of tutorials on how to write and map a servlet. First step would be to get a simple "hello world" servlet running. Then you can use that as a pattern to write the upload servlet.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Converting a JSP to a servlet is easy.
Copy everything between the <% and %> tags, and paste it into the doPost method of a servlet.

Taking a quick glance you can pull out the bit that checks for method of type head, and put the relevant code into the doHead method of a servlet.
 
victor bwalya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone rewrite this code converting it into a servlet ? because i have gone through alot of tutorials concerning the same,but i still cant get it done. i guess there is some thing that am not doing right ;
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then tell us what the problems you are having are. This is not the place to try and get someone to do your work for you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!