reddy palwai

Greenhorn
+ Follow
since Nov 06, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by reddy palwai

Thanks for all the suggestions. I'll try storing the images as longraw or store just the hyperlinks.
Is there a way to read all the files from a particular directory?? People can ftp their image files to this directory and a servlet can retrieve all the files as images from this directory.<img src="images/hi.gif">
22 years ago
I have used orielly's classes for multipart file transfers. I downloaded the package from their web site. It worked!!
22 years ago
http://www.vbsoftindia.com/vbsoft%20faq/jsp.html
JSP pages are compiled into servlets, so theoretically you could write servlets to support your web-based applications. However, JSP technology was designed to simplify the process of creating pages by separating web presentation from web content. In many applications, the response sent to the client is a combination of template data and dynamically-generated data. In this situation, it is much easier to work with JSP pages than to do everything with servlets.

22 years ago
Hi all, here is my problem
I need to insert and retrieve the image file from the database.
I am using http://www.servlets.com/cos/index.html
package for dealing with multipart request when uploading the file.
I am then inserting the file into the database.
I think it is inserting the file properly into the database.
now I need to retrieve the image blob from the database and display it in the browser.
here is my servlet code :

import java.util.*;
import java.io.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class blobview extends HttpServlet
{
private BLOB myblob;
private String mname="";
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("image/gif");
Connection con=null;
Statement stmt =null;
ResultSet resl=null;
String flname=req.getParameter("fname");
try
{
DriverManager.registerDriver( new oracle.jdbc.OracleDriver());
con =DriverManager.getConnection("jdbc racle ci8:@test1","rpalwai","rp6701");
con.setAutoCommit(false);
stmt = con.createStatement();
resl = stmt.executeQuery("SELECT NAME, BFILE FROM SAMPLEBLOB WHERE NAME = '" + flname + "'");

while( resl.next() )
{
//mname=resl.getString("NAME");
myblob = ((OracleResultSet)resl).getBLOB ("BFILE");
InputStream blobStream = myblob.getBinaryStream();

int chunkSize=myblob.getChunkSize();
byte [] byteBuffer=new byte[chunkSize];
String saveFile=targetDir + flname;
FileOutputStream fileOutStream = new FileOutputStream(flname);
int bytesRead;
while((bytesRead = blobStream.read(byteBuffer))!= -1)
{
fileOutStream.write(byteBuffer);
}
fileOutStream.close();
blobStream.close();
}
}
catch (SQLException e)
{
throw new IOException("Database Error querying insert new file"+e.getMessage());
}
finally
{if(stmt!=null)
{
try
{
stmt.close();
con.close();
//con.commit();
}
catch(SQLException e)
{
}
}
}
}
}
This code does not work. it just displays an image icon not actual image.
please help
thanks,
reddy
22 years ago
Thanks Sony.
22 years ago
Thanks Sony for your Response. I have another question now about file uploading that I have just posted.
22 years ago
Hi ,
I have a question about file uploading in servlets.
I have an html form with an input file type as FILE and enctype as multipart/form-data.
<FORM ENCTYPE="multipart/form-data" ACTION="blobinsert" METHOD=POST>
<INPUT TYPE=FILE NAME="uploadfile">
In my servlet I need to get the parameters from the html form.
For text and other input types we can get the parameters using getParameter(). But how can I get the data from when file is uploaded?
Please Help!! this is kind of Urgent.
Thanks in advance.
reddy
22 years ago
hello,
I have a question...
I am using BLOBs to insert image file into the database.
After inserting an Empty_blob() into the database. I want to use blob.putBytes(long,byte[]) method to load the bytes into the blob.
I am getting the parameter from the html form.
AS request.getParameter("blob") gets the type String. I need to convert it into byte[]. Is it possible in java?? please help.
Can anyone please send me some sample code for inserting and retrieving BLOBs from the database. I dont have much experience in java servlets.
Thanks,
Reddy
22 years ago
Here is my simple code
Html file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>A Sample FORM using POST</TITLE>
</HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">A Sample FORM using POST</H1>
<FORM ACTION="test" METHOD="POST" name=samp>
Name:
<INPUT TYPE="TEXT" NAME="name"><BR>
<INPUT TYPE="SUBMIT" VALUE="Submit Order">
</FORM>
</BODY>
</HTML>

SERVLET

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class test extends HttpServlet
{
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
String para = req.getParameter("name");
ServletOutputStream out = res.getOutputStream();
// set content type and other response header fields first
res.setContentType("text/html");
// then write the data of the response
out.println("<HEAD><TITLE> Testing </TITLE></HEAD><BODY>");
out.println("<h1> "+para+"</h1><br>");
}
}
22 years ago
Thanks Neil,
response.setContentType("text/html");
22 years ago
I am trying to post information from an html file to a servlet.
I have
<FORM ACTION="test" METHOD="POST" name=sample>
in my html file
and
I have
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
in my java servlet file.
My Java is compiling fine, but when I post information from my html file, I am getting the following error
/////////////////
Method Not Allowed
The requested method POST is not allowed for the URL.
//////////////////
I tried changing POST to GET...then it is downloading the file instead of opening it.
May be something is wrong with configuration.
Please help.
thanks in advance,
reddy
22 years ago