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
|