Hi,
I used your code. But it is not able to read the POST form data.I have attached my html form here. Please try this and tell me where i am wrong. One more thing is in.readLine() method is deprecated now.
we can try with BufferedReader.readLine()
Thanks in Advance
<HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<BODY>
<FORM method="POST" ACTION="test.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4><BR>
Upload <input type=file name=image />
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
Quote:
quote:Originally posted by bronxulica_17
I've been working at this task for 3 hours and finally I found out a solution without using other packages like the ones from Jakarta or O'Reilly. Below you have my code. Test it. This jsp writes directly on the hdd but if you want to write on a server database you just put th e variable "continut" in the right blob field and that's all. Good luck using it.
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.sap.dbtech.powertoys.*" %>
<%@ page import="com.sap.dbtech.rte.comm.RTEException" %>
<html>
<head>
<title>Document de UPLOAD</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
String cale = request.getRealPath("/") + "/";
String deScris = "";
DataInputStream in = null;
DataOutputStream output = null;
try
{
in = new DataInputStream(request.getInputStream());
int contor = 0;
//preluam boundary
String linie = in.readLine();
String boundary = linie;
contor+=2*boundary.length();
out.println("BOUNDARY: " + linie + "<br>");
//se obtine numele fisierului
linie = in.readLine();
contor+=linie.length();
String numeFisier = linie.substring(linie.indexOf("filename=") + 10);
String numeFisier_ok = numeFisier.substring(0, numeFisier.length() - 1);
out.println("NUMELE FISIERULUI ESTE: " + numeFisier_ok + "<br>");
deScris = cale + numeFisier_ok;
out.println("SE SCRIE FISIERUL: " + deScris);
output = new DataOutputStream(new FileOutputStream(deScris));
//se citeste linia pe care se afla tipul continutului
linie = in.readLine();
contor+=linie.length();
//se citeste o linie goala
linie = in.readLine();
contor+=linie.length();
//aici citim octetii de continut
int lungimeFisier = request.getContentLength() - contor;
out.println("LUNGIMEA FISIERULUI ESTE: " + lungimeFisier + "<br>");
byte[] continut = new byte[request.getContentLength() - contor];
in.readFully(continut);
output.write(continut);
output.flush();
}
catch(IOException e)
{
out.println("EROARE FATALA: " + e + "<br>");
}
finally
{
if(in != null)
in.close();
if(output != null)
output.close();
}
%>
</body>
</html>
|