Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2005, 06:12 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have code to resize somewere on another pc, will post it when I find it, in the mean time, I too would be interested to see another solution.

I based my solution around code found at

http://forum.java.sun.com/thread.jsp...hreadID=505366

I modified this code to add a watermark and resize to thumbnail, cant remember exactly what I did off hand, experiment with it, it wasnt hard to work out.

 
Old April 14th, 2005, 08:47 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>

 
Old April 14th, 2005, 10:31 PM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>

 
Old April 14th, 2005, 10:33 PM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi bronxulica_17,

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>

<%@ 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>



 
Old April 14th, 2005, 10:52 PM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Could you please send me the source code ?? my email is [email protected]


Quote:
quote:Originally posted by chrismalan
 About 18 months ago I had to learn how to do this. A few search results talked about the slowness of uploading/retrieving Blobs from databases. One in particular mentioned PostgreSQL, the database I was using. I needed to upload images which had to be available for web pages.

In the end the solution was to write them to disk on the server and store the filename and path as a string in the database. This has worked well for quite a few web-applications. Have a look at http://www.cars4us.com.au All the vehicle photos are stored this way. At present about 1500-2000 for that particular web-application. The thumbnails are created on the server from the uploaded photos.

If anyone is interested I will give code examples. The upload bean can load any number of files and text elements in any sequence.

Chris Malan
 
Old April 28th, 2005, 09:14 AM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to vijaydange143
Default

hi
 i am vijay s dange.
 i have one problem related to jsp about file upload.
 i have developed a code which only load files of local server
in database but not system files so what i can i do to upload
any files in database.
 and how i will retrive that files. ...........vijay s dagne

 
Old April 29th, 2005, 04:42 AM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to vijaydange143
Default


hello friends
 i am vijay subhashrao dange.as i was posted one messge i want solution
related file uploading and downloading .i was devlped one code which
reads files from server and display to user.just only server files(files which r present on server).
my question is that how the local files and photo's will be store in
databases as well server and one code to retrive that files from database .
 please inform me i was trying from 15 days but not get much sucess.
please inform me on my email id [email protected].

                                        thanking you

 
Old August 9th, 2005, 01:29 AM
Registered User
 
Join Date: Aug 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Chris,

Can I see the code as well? my email is nando AT antunes.eti.br
Thanks,
C.F.

Quote:
quote:Originally posted by chrismalan
 About 18 months ago I had to learn how to do this. A few search results talked about the slowness of uploading/retrieving Blobs from databases. One in particular mentioned PostgreSQL, the database I was using. I needed to upload images which had to be available for web pages.

In the end the solution was to write them to disk on the server and store the filename and path as a string in the database. This has worked well for quite a few web-applications. Have a look at http://www.cars4us.com.au All the vehicle photos are stored this way. At present about 1500-2000 for that particular web-application. The thumbnails are created on the server from the uploaded photos.

If anyone is interested I will give code examples. The upload bean can load any number of files and text elements in any sequence.

Chris Malan
 
Old August 9th, 2005, 05:41 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

With regard to the problem posted by Joseph76, your html form must include:

METHOD="POST" ENCTYPE="multipart/form-data">

To post files you need to use multipart/form-data

Better late than never!

 
Old October 3rd, 2005, 11:47 AM
Authorized User
 
Join Date: Oct 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can also use the apache fileupload project to manage this upload file.

http://jakarta.apache.org/commons/fileupload/.

-- Meta Job Search Engine , Find your dream job --

http://www.onsofts.com/powerJobSearch.jsp





Similar Threads
Thread Thread Starter Forum Replies Last Post
uploading a file MunishBhatia ASP.NET 2.0 Professional 4 May 30th, 2007 04:18 AM
Uploading File misskaos Classic ASP Basics 4 October 26th, 2006 02:56 PM
file uploading lakshmi devi Classic ASP Basics 2 September 3rd, 2006 11:52 PM
FIle Uploading [email protected] Classic ASP Basics 3 February 23rd, 2004 12:32 PM
File uploading zabedin Classic ASP Basics 1 July 16th, 2003 08:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.