Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet not running

 
deep raj
Ranch Hand
Posts: 186
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 665
4
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic