Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
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:

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;
Statement st1=con.createStatement();
ResultSet rs1 = st1.executeQuery("select image from picture where pictureid='1'");
String imgLen="";
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len); 

} catch (Exception e){



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

 <H1>HTTP Status 404 - /peggie/servlet/sg.edu.nyp.sit.RetrieveImage
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

Coulde you guys help me solve it asap.
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

You servlet mapping code might help to identify the problem.
404 is - resource not found error!
- Rakesh

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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.