jQuery in Action, 2nd edition*
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 Android Security Essentials Live Lessons this week in the Android 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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: servlet not running
 
Similar Threads
displaying image from database
display image after retrieving it from database?
Displaying an image from byte[] into JSP
Display Image in JSP retrieved from database by servlet
Exception with displaying image