Shrikant Kulkarni

Ranch Hand
+ Follow
since May 10, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shrikant Kulkarni

Hi,

<input type="file" /> gives a browse button in a web browser. But the same code doesn't work in PDA browser using XHTML-MP language.
So is there any other alternative to get the browse button in PDA browser?

Please help which is requied very urgent.
Thanks all,
The issue got solved by using
request.setAttribure("<name>",object);
in JSP and getting that request attribute from JSP by using
String name = (String)request.getAttribure("<name>");
in the forwarded servlet.
15 years ago
Yes they are not null, i checked it.
15 years ago
Dear,
You can use apache's common.FileUpload and common.io packages which serves your purpose.
While you are inserting image into the BLOB column of the DB, first you insert empty BLOB object. And again you get the BLOB column using a SELECT sql statement open a OutputStream.
I think this code may help you
prapredStatement = connection.prepareStatement("select image from image_upload where log_id = ? and image_name = ? for update");
prapredStatement.setInt(1,logId);
prapredStatement.setString(2,imageName);
// Execute the SQL statement
resultSet = prapredStatement.executeQuery();
// Retrieve Blob streams for Image column, and load the sample file
if(resultSet.next())
{
// Get the Blob locator and open output stream for the Blob
Blob mapBlob = resultSet.getBlob(1);
OutputStream blobOutputStream = ((oracle.sql.BLOB)mapBlob).getBinaryOutputStream();
// Open the FileInputStream for insertion into the Blob column
InputStream sampleFileStream = new FileInputStream(saveTo);
// Buffer to hold chunks of data to being written to the Blob.
byte[] buffer = new byte[10* 1024];
// Read a chunk of data from the sample file input stream, and write the chunk to the Blob column output stream.
//Repeat till file has been fully read.
int nread = 0; // Number of bytes read
while( (nread= sampleFileStream.read(buffer)) != -1 ) // Read from file
blobOutputStream.write(buffer, 0, nread); // Write to Blob
// Close both streams
sampleFileStream.close();
blobOutputStream.close();
}
15 years ago
Hi,

I have a JSP page, in this page i am using RequestDispacher to forward the request to a servlet.
The is as below
RequestDispatcher d=application.getRequestDispatcher("/EnlargeImage");
d.forward(request, response);

In the above code "/EnlargeImage" is the URL pattern for the servlet mapping mentioned in the web.xml.

The request is forwarded to the servlet successfully. But when i try to get parameters from the request, i get null values.

Can any one tell me what is the problem and how to solve it.
[ June 01, 2006: Message edited by: Bear Bibeault ]
15 years ago
Hi,
I have solved this problem by inserting empty_blob() while inserting the BLOB image. Retrieve the row just inserted, and lock it for insertion of the BLOB columns.
prapredStatement = connection.prepareStatement("select image from image_upload where log_id = ? and image_name = ? for update");
prapredStatement.setInt(1,logId);
prapredStatement.setString(2,imageName);
// Execute the SQL statement
resultSet = prapredStatement.executeQuery();
// Retrieve Blob streams for Image column, and load the sample file
if(resultSet.next())
{
// Get the Blob locator and open output stream for the Blob
Blob mapBlob = resultSet.getBlob(1);
OutputStream blobOutputStream = ((oracle.sql.BLOB)mapBlob).getBinaryOutputStream();
// Open the FileInputStream for insertion into the Blob column
// saveTo is File from which where you are getting the image
InputStream sampleFileStream = new FileInputStream(saveTo);
// Buffer to hold chunks of data to being written to the Blob.
byte[] buffer = new byte[10* 1024];
// Read a chunk of data from the sample file input stream, and write the chunk to the Blob column output stream.
//Repeat till file has been fully read.
int nread = 0; // Number of bytes read
while( (nread= sampleFileStream.read(buffer)) != -1 ) // Read
//from file
blobOutputStream.write(buffer, 0, nread); // Write to Blob
// Close both streams
sampleFileStream.close();
blobOutputStream.close();
}
Hi,

I am using apache's FileUpload to upload images into the data base. I am using oracle 10g data base and image is stored as a BLOB object. I am connecting to the DB using JDBC thin drive.
I can upload small images of below 4KB but bigger than that.
When I wanted to upload some big images of size 50-100KB, i am getting "Data size is bigger then max size".


Any help please.
Just to confirm? where is the name parameter required for servlet?

Hi

Name paramter required for servlet means??
<servlet> and <servlet-mapping> entries right??

If yes, then i have made entries in web.xml and it is as below

<servlet>
<servlet-name>download</servlet-name>
<servlet-class>disable.DisableText</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>download</servlet-name>
<url-pattern>/download</url-pattern>
</servlet-mapping>
15 years ago
Size of the image is aroung 150KB
op : It is an outputstream which i useed earlier but now i am not using it.. so op.flush(), op.close() doesn't have any significance.


All the images are jpeg only.
15 years ago
Hi
Broken image means there is a space in the browser for Image but image isn ot displyed. Like we use to get this when we mention a image but that specific image the browser can't find.

I mentioned height and width also but not helped.
Any idea please.

Shrikant
15 years ago
Hi All,

I am getting the image from the database (in a servlet), I want to display that image in JSP. But in JSP i am getting a broken image instead of an proper image.

Here is the servlet code :

public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String strImageName = req.getParameter("name");
res.reset();
res.setContentType("image/jpeg"); //JPG file
try{
conn = DisableText.getConnection(); // Connecting to the database
pstmt = conn.prepareStatement("select image from image_upload where image_name=?");
pstmt.setString(1,strImageName);
rs = pstmt.executeQuery();
while(rs.next())
{
byte[] imgBytes = rs.getBytes(1);
res.setContentLength(imgBytes.length);
res.getOutputStream().write(imgBytes);
}
op.flush();
op.close();
}
}
catch (Exception e)
{
throw new ServletException("Unable to print image"+e.getMessage());
}
}


Here is the JSP code:
<html>
<body>
<form name="delete" action="download" method="post" >
<table>
<tr>
<td>
<IMG src="<%=request.getContextPath() %>/DisableText"> // DisableText is the servlet class name
</td>
</tr>
</table>
</form>
</body>
</html>


Can any one help me please.

Shrikant
15 years ago
Hi All,

I am getting the image from the database (in a servlet), I want to display that image in JSP. But in JSP i am getting a broken image instead of an proper image.

Here is the servlet code :

public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String strImageName = req.getParameter("name");
res.reset();
res.setContentType("image/jpeg"); //JPG file
try{
conn = DisableText.getConnection(); // Connecting to the database
pstmt = conn.prepareStatement("select image from image_upload where image_name=?");
pstmt.setString(1,strImageName);
rs = pstmt.executeQuery();
while(rs.next())
{
byte[] imgBytes = rs.getBytes(1);
res.setContentLength(imgBytes.length);
res.getOutputStream().write(imgBytes);
}
op.flush();
op.close();
}
}
catch (Exception e)
{
throw new ServletException("Unable to print image"+e.getMessage());
}
}


Here is the JSP code:
<html>
<body>
<form name="delete" action="download" method="post" >
<table>
<tr>
<td>
<IMG src="<%=request.getContextPath() %>/DisableText"> // DisableText is the servlet class name
</td>
</tr>
</table>
</form>
</body>
</html>


Can any one help me please.

Shrikant
15 years ago
Hi,
I am new to handling of BLOB objects.
i want to display all the images present in a particular table for a particular ID: The sql query is as below
select image from image_upload where log_id=?
Note: image is BLOB type

In jsp:
I get a ResultSet (rs):

<%
while(rs.next())
{
InputStream inputStr = rs.getBinaryStream(1);
byte[] bytearray = new byte[4096];
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int nbytes = 0; // Number of bytes read
while( (nbytes = inputStr.read(bytearray)) != -1 )
{
outStream.write(bytearray, 0, nbytes);
}
outStream .close();
inputStr.close();
%>
<tr>
<td valign = "baseline">
<img align = "bottom" src = "<%=imageName%>" alt="<%=imageName%>" height="100" width="100"/>
</td>
</tr>

But in JSP page it displayed a broken image link, not the image which i got it from database.

Can any one please tell me what piece of code i should write in order to display all the images??
15 years ago
JSP
Hi Carl,

Really a greate analysis. It worked out. It is fixed my problem.
Thanks a lot.

Shrikant
15 years ago
Hi All,
I want to upload some .jpeg images from a PC into a DB for that i am writing a java application. I am using apache's fileupload API's for this.
The code is given below:


<%@ page import="org.apache.commons.fileupload.*, java.util.*, java.lang.Exception, oracle.jdbc.driver.OracleDriver, java.sql.*, java.io.*" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form action="disable.jsp" method="post" enctype="multipart/form-data" name="disable">
<br/>
Choose a photo to be uploaded to the WAP server:
<input name="myFile" type="file"/><br/>
On the WAP server, save the file as: (Enter something here if you want the file to be saved in a different file name.)
<input name="filename" type="text"/>
<hr/>
<input type="submit"/>
<input type="reset"/>
<br/>
</form>
</body>
</html>

<%
if (FileUpload.isMultipartContent(request))
{
DiskFileUpload diskFileUpload = new DiskFileUpload();
List fileItemsList = diskFileUpload.parseRequest(request);
String optionalFileName = "";
FileItem fileItem = null;

Iterator it = fileItemsList.iterator();
while (it.hasNext())
{
FileItem fileItemTemp = (FileItem)it.next();
if (fileItemTemp.isFormField())
{
if (fileItemTemp.getFieldName().equals("filename"))
optionalFileName = fileItemTemp.getString();
}//end of if(fileItemTemp.isFormField()) condition
else
fileItem = fileItemTemp;
}// end of while loop

if (fileItem!=null)
{
String fileName = fileItem.getName();
/* Save the uploaded file if its size is greater than 0. */
String sFileName = fileName;
if (fileItem.getSize() > 0)
{
if (optionalFileName.trim().equals(""))
fileName = (new File(fileName)).getName();
else
fileName = optionalFileName;
File saveTo = new File(sFileName);
FileInputStream fipImage = null;
int result =0;
Connection conn = null;
ResultSet rs = null;
try {
conn = DisableText.getConnection();
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO image_upload VALUES( ?, ? , ?)");
pstmt.setInt(1,100);
fipImage = new FileInputStream(saveTo); // #### Error occurs
pstmt.setBinaryStream( 3, fipImage, (int)( saveTo.length() ) );
pstmt.setString(2, "pic");
result = pstmt.executeUpdate();
if(result != 0){
%>
The uploaded file has been saved successfully.
<%
}// end of if(result != 0) condition
}// end of try block
catch (Exception e){
e.printStackTrace();
%>
<%=e%> <br/>
An error occurred when we tried to save the uploaded file. <br/>
<%
} // end of catch block
}// end of if(fileItem.getSize() > 0) condition
} // end of if(fileItem!=null) condition
}// end of if(FileUpload.isMultipartContent(request)) condition
%>


The EAR file of this application is created and deployed in the application server. When application is accessed through IE browser and tried to upload a .jpeg image, it gives FileNotFound error.
(The "####" sign indicates the line where the FileNotFound error occurs in the code written above.)
But the same code works in the Debug mode. The same application when deployed in the server and accessed through IE browser it gives FileNotFound error.

Can any one please help on in solving this problem.
Thanks well in advance

Regards.
SK
15 years ago