This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes servlet not running Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet not running" Watch "servlet not running" New topic
Author

servlet not running

deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
my servlet file is
////DisplayImage.java

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

public class DisplayImage extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
System.out.println("dfgdfg");
String connectionURL = "jdbc:mysql://localhost:3306/workplanner";
java.sql.Connection con=null;
Statement st1;
try{
String s1=request.getParameter("var");
System.out.println(s1);
int h=9;
// int h=Integer.parseInt(s1);
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(connectionURL,"root","");
st1=con.createStatement();
ResultSet rs1 = st1.executeQuery("select image from employee_personal where emp_id ="+h);
String imgLen="";
while(rs1.next()){
imgLen = rs1.getString(1);
System.out.println(imgLen.length());
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);
response.reset();
response.setContentType("image/jpg");
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();

}
st1.close();
response.getOutputStream().close();
} catch (Exception e){
e.printStackTrace();
}
}
}




i wrote in web.xml file like this
<servlet>
<servlet-name>Display</servlet-name>
<servlet-class>DisplayImage</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Display</servlet-name>
<url-pattern>/DisplayImage</url-pattern>
</servlet-mapping>


i called the servlet like this
img src="/DisplayImage?var=2"



but when i am running it as
http://localhost:8585/DisplayImage
it shows nothing

what is the problem and how can i solve it?
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

amrita singhal wrote:
but when i am running it as
http://localhost:8585/DisplayImage
it shows nothing



where is the parameter var in the url?, probably you would have got NullPointerException when you run this, check your server logs..


Regards, Prasad
SCJP 5 (93%)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button. Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet not running
 
Similar Threads
Exception with displaying image
Display Image in JSP retrieved from database by servlet
Displaying an image from byte[] into JSP
displaying image from database
display image after retrieving it from database?