Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets 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 1st, 2009, 01:18 PM
Authorized User
 
Join Date: Jan 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Servlet have error:(

Hello, I am peggie. I would like to retrieve image from the database and display it on the servlet. However, it result in an error.

Here are my codes:

Code:
 
package sg.edu.nyp.sit;


import java.io.IOException;
import java.io.InputStream;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class RetreiveImage
*/
public class RetrieveImage extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* Default constructor. 
*/
public RetrieveImage() {
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String connectionURL = "jdbc:mysql://localhost:3306/images";
java.sql.Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(connectionURL,"root","");
Statement st1=con.createStatement();
ResultSet rs1 = st1.executeQuery("select image from picture where pictureid='1'");
String imgLen="";
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len); 
System.out.println("index"+index);
st1.close();
response.reset();
response.setContentType("image/jpg");
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush(); 

}
} catch (Exception e){
e.printStackTrace();




}


}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
Code:
}

Code:
 <H1>HTTP Status 404 - /peggie/servlet/sg.edu.nyp.sit.RetrieveImage
Code:
type Status report
message /peggie/servlet/sg.edu.nyp.sit.RetrieveImage
description The requested resource (/peggie/servlet/sg.edu.nyp.sit.RetrieveImage) is not available.
Apache Tomcat/6.0.18
</H1>

Coulde you guys help me solve it asap.
Thanks:D
Reply With Quote
  #2 (permalink)  
Old July 7th, 2009, 09:28 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

You servlet mapping code might help to identify the problem.
404 is - resource not found error!
__________________
- Rakesh
http://iam-rakesh.blogspot.com
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
servlet shiveka Servlets 1 October 9th, 2006 08:26 PM
error while compiling servlet in Weblogic8.1 adityasharma003 Servlets 0 April 12th, 2006 05:30 AM
Need help in servlet arunj82 Apache Tomcat 0 March 15th, 2006 07:16 AM
servlet accessing MySql ....error simplyAns MySQL 1 January 17th, 2006 03:41 AM
Tomcat and servlet error - beginner's question blues_traveler Apache Tomcat 5 January 15th, 2005 09:37 PM



All times are GMT -4. The time now is 06:22 AM.


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