Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 9th, 2003, 07:23 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get File type before save to database.

Hello,

How to get File type before save to database in a JSP page.

One confusion I have, while I am trying to upload file from Client machine and saving it to DataBase,

From saving the file to database I am using Prepared Statement here for

[1] for image type file we are using setBinarySream()
[2] for txt or doc file type we are using setAsciiSream()

* please tell is some general stream format is for all type of files, or we have to set Stream according to file.

* if different file is having different stream then please tell me how we can get the type of file befoe uploading so that we will use the right Stream while before save to database.

Please tell me with code.
Do replay
Regards.
Reply With Quote
  #2 (permalink)  
Old July 19th, 2003, 05:00 AM
Authorized User
 
Join Date: May 2003
Location: New Delhi, Delhi, India.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
Answer to some of your Quires
Q.How to get File type before save to database in a JSP page.
Ans. When the browser send the content of a file it also send file information and the content type of the file. So to get the content type or the file type one has to parse this information. Following is the code which extracts file name.
ServletInputStream readstream = req.getInputStream();
int i,number=0;
while((i = readstream.readLine(data,0,data.length)) != -1)
{
    String str1 = new String(data);
    str1 = str1.trim();
    if(str1 == null)
        break;
    //This if block extracts the file name
        if(str1.startsWith("Content-Disposition:"))
    {
        int beginpos = (str1.indexOf("filename="));
        int endpos = (str1.length());
                String pathname = str1.substring(beginpos,endpos);
        int namepoint = pathname.lastIndexOf('\\');
        int nameendpoint = pathname.lastIndexOf('\"');
        String namef = pathname.substring((namepoint+1),(nameendpoint));
        setfilename(namef);
        if (createFile())
        writedata = true;
    }

Q. please tell is some general stream format is for all type of files, or we have to set Stream according to file.
Ans. I suggest you can use setBinaryStream()for all the files.

Yashraj Chauhan
Java\J2EE Specialist
Wiley Support Team
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save database schema to XML file brettk_1 General .NET 2 September 16th, 2006 04:27 AM
Save xlsheet file in a database nachi_hota ADO.NET 1 August 4th, 2006 05:08 AM
Save BINARY FILE in ACCESS database gasma1975 Access 4 February 10th, 2005 12:16 PM
<input type="File"> - Specify File Type and Path gp_mk Classic ASP Basics 2 August 2nd, 2004 03:07 AM
How to get File type before save to database monika_jain_99 J2EE 0 July 9th, 2003 07:12 AM



All times are GMT -4. The time now is 05:08 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.