This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet auto loading

 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want the servlet to be auto loaded.
following is my html:
<img src="servlet file?id=1">
now whenever i load my html file ,i want that servlet file should get automatically loaded
So which HTTP method i can use?
plz help
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dhanashree,
Do you mean that you want the Servlet's generated results to be cached in the client's browser so it is loaded faster next time it is accessed? Or do you mean that you want the Servlet to be loaded into the web container initially so that the very first time it is accessed the client doesn't have to wait while the ClassLoader finds the resource and loads it all into memory?
If you wanted the first thing, and your Servlet is generating an image, there are various ways to precache images. I would suggest you search the Integer for various solutions. I'm going to assume that you want the second solution. In that case there is an auto-load deployment descriptor you can use to achieve what you want:

Does that answer your question?
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want the first thing. I want to catch the image sent by servlet everytime when client go for html page.Means that servlet should get automatically loaded.
Originally posted by Nathaniel Stoddard:
Dhanashree,
Do you mean that you want the Servlet's generated results to be cached in the client's browser so it is loaded faster next time it is accessed? Or do you mean that you want the Servlet to be loaded into the web container initially so that the very first time it is accessed the client doesn't have to wait while the ClassLoader finds the resource and loads it all into memory?
If you wanted the first thing, and your Servlet is generating an image, there are various ways to precache images. I would suggest you search the Integer for various solutions. I'm going to assume that you want the second solution. In that case there is an auto-load deployment descriptor you can use to achieve what you want:

Does that answer your question?
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you wanted the first thing, and your Servlet is generating an image, there are various ways to precache images. I would suggest you search the Integer for various solutions.

Can u plz tell me what is Interger for various solutions?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, sorry about that.
"Integer" should be "Internet". See what you people do to me!!
I'd suggest reposting this (with a better re-wording) in the HTML forum. I'm sure they'd be able to help you out. I'm not exactly an HTML/JavaScript expert these days.
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following is my html file.
<BODY>
<img src="http:\\127.0.0.1:8080\examples\servlet\id2?id=1">
</BODY>
Servlet file:These r the 3 types by which i can send image to front end
1>String s = request.getParameter("id");
if (s.equals("1")){
String s1 = "http://www.az-maz.com/wall/fantasy/096.jpg";
PrintWriter out = response.getWriter();
out.println("<img src=\"" + s1 + "\">" );
}
2>public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
String s = request.getParameter("id");
if (s.equals("1")){
sponse.setContentType("image/jpeg");
URL yahoo = new URL("http://www.az-maz.com/wall/fantasy/096.jpg");
BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream()));
PrintWriter out = response.getWriter();
String input;
while((input = in.readLine()) != null){
out.println(input);
}
}
}
Getting the image but not in proper format
3>public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
String url=new String();
String s = request.getParameter("id");
if (s.equals("1")){
response.setContentType("image/jpeg");
url="http://www.az-maz.com/wall/fantasy/096.jpg";
File f = new File(url);
FileInputStream fin = new FileInputStream(f);
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(fin);
BufferedImage image = decoder.decodeAsBufferedImage();
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
}
}
But i am getting just a Small Cross in front end with 1 and 2.
Can anybody plz help me
thanx
<img src
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic