i hve used upload bean for uploading files...
im using netbeans and while compiling its says javazoom package does not exist...
any solutions ??

Dani AI

Generated

A short, practical diagnosis for (and thanks to for the jar tip earlier).

You can save the uploaded file but still get null for the text fields because the request is multipart/form-data. The servlet container does not populate the normal parameter map for multipart requests, so the usual request-parameter helpers will return null unless the multipart body is parsed. Reading the raw input stream into a byte array (as in the posted JSP) is why those text fields are not available.

Two robust options to fix this:

  • Use a library such as Apache Commons FileUpload to parse the multipart request into form fields and file items. The library returns form fields separately from file items so you can read the song name and album reliably.
  • If running on Servlet 3.0+ use the built-in Part API (MultipartConfig + request.getPart / request.getParts) — this avoids external jars and is simpler when used from a servlet.

Practical advice specific to the code shown:

  • Avoid converting the entire request bytes into a Java String for parsing binary data; that risks corruption. Parse boundaries at the byte level or use a library.
  • When reading the input stream, pass the remaining byte count to read(), not the full form length each loop.
  • Do not build SQL by concatenating user values (album/song). Use PreparedStatement with parameter placeholders and a fixed table name. Closing streams, statements and connections in finally blocks or via try-with-resources is essential.
  • Move upload parsing out of a JSP into a servlet or helper class. JSPs should be view code; servlet or a helper library keeps upload logic clearer and safer.

Documentation:

Recommended Answers

All 4 Replies

Obviously you missing download4j.jar that should be inside lib folder on your server
Next time please provide full info and not expect us to search for what ever you trying to do...

thnx nw i can upload a file...
but when i send a value from html page to jsp page and print it
it displays null
whts the problem...
songname=request.getParameter("name");
this is hw i get the value from html page....

You should support your problems with relevant coding samples...

this my jsp file..

<%@page contentType="text/html" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
String saveFile = "",album="",location="",songname="";
String contentType = request.getContentType();
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
{
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
songname=request.getParameter("name");
album=request.getParameter("album");
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") +
1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
String folder = "F:/games/";
FileOutputStream fileOut = new FileOutputStream(folder + saveFile);
out.print("Saved here: " + saveFile);
//fileOut.write(dataBytes);
location=folder+saveFile;
try{
      Class.forName("org.apache.derby.jdbc.ClientDriver"); 
      Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/Xonicmp3","Xonic","Xonic");                  
      ResultSet rs=null;
      Statement stmt=con.createStatement();
      String sql=("insert into "+album+" values('"+songname+"','"+saveFile+"','"+location+"')");
      stmt.executeUpdate(sql);
      rs.close();
      con.close();
    }catch(Exception e)
                        {
                    out.println(e.toString());
                }
out.println(location);
out.println(album);
out.println(songname);
out.println(saveFile);
out.println(location);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
//out.println("Uploading your file. Please wait...");
}
%>

html file is

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Upload</title>
<style type="text/css">
.style1 {
	font-size: 18pt;
	color: #666666;
	font-family: "Harlow Solid Italic";
}
.style2 {
	font-family: Calibri;
}
</style>

</head>
<body bgcolor="black">
<form method="post"  name="upform" enctype="multipart/form-data" action="fileUpload.jsp">
<table align="center">
<tr>
<td height="1000" width="800" background="up.jpg">
<div style="position: absolute; width: 482px; height: 392px; z-index: 1; left: 343px; top: 429px" id="layer1">
	<div style="position: absolute; width: 231px; height: 24px; z-index: 7; left: 212px; top: 197px" id="layer8">
		<select name="album">
		<option>Akon</option>
                <option>Ashlee Simpson</option>
                <option>Avril</option>
                <option>Backstreet Boys</option>
                <option>Blue</option>
                <option>Britney Spears</option>
                <option>Hilarry Duff</option>
                <option>Linkin Park</option>
                <option>Michael Jackson</option>
                <option>WestLife</option>
                <option>Others</option>
		</select></div>
	<div style="position: absolute; width: 200px; height: 20px; z-index: 6; left: 212px; top: 147px" id="layer7">
		<input name="name" type="text" style="width: 200px"></div>
	<div style="position: absolute; width: 263px; height: 25px; z-index: 5; left: 213px; top: 94px" id="layer6">
		<input name="File1" id="file" type="file" style="width: 232px; height: 25px"></div>
	<div style="position: absolute; width: 116px; height: 27px; z-index: 4; left: 49px; top: 196px" id="layer5" class="style2">
		Album</div>
	<div style="position: absolute; width: 151px; height: 31px; z-index: 1; left: 20px; top: 24px" id="layer2" class="style1">
	Upload</div>
	<div style="position: absolute; width: 45px; height: 21px; z-index: 2; left: 51px; top: 94px" id="layer3" class="style2">
		<label id="Label1">Song </label></div>
	<div style="position: absolute; width: 97px; height: 31px; z-index: 3; left: 50px; top: 142px" id="layer4" class="style2">
		Song Name</div>
	<div style="position: absolute; width: 101px; height: 24px; z-index: 8; left: 186px; top: 281px" id="layer9">
		<input name="upload" type="submit" value="Upload" style="width: 95px"></div>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.