on 08-11-2006 6:08 PM
Hello, i have EAR + DataBase, how can i upload images into the database within java?
hi?
How did you use this code. it doesnt work my j2ee engine. I found problem in.read statement. because if my read parameter above integer.maxvalue(32768) it gives null exception.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<!-- upload.jsp -->
<%
System.out.println("Start...");
String contentType = request.getContentType();
System.out.println("Content type is :: " + contentType);
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;
}
out.println("<BR><BR>");
out.println("<BR><BR>");
//out.println(dataBytes.toString());
out.println("<BR><BR>");
out.println("<BR><BR>");
String file = new String(dataBytes);
String saveFile =
file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile =
saveFile.substring(
saveFile.lastIndexOf("
") + 1,
saveFile.indexOf("\""));
//out.println(saveFile);
out.print(dataBytes);
int lastIndex = contentType.lastIndexOf("=");
String boundary =
contentType.substring(lastIndex + 1, contentType.length());
//out.println(boundary);
out.println("<BR><BR>");
out.println("<BR><BR>");
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 data = file.substring(startPos, endPos);
out.println(data);
out.println("<BR><BR>");
out.println("<BR><BR>");
FileOutputStream fileOut = new FileOutputStream(saveFile);
//fileOut.write(dataBytes);
fileOut.write(data.getBytes());
fileOut.flush();
fileOut.close();
out.println("File saved as " + saveFile);
}
%>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I mean: User with Admin rights(UME ROLES), uploads images into j2ee application from servlet
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.