• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

servlet auto loading

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please help
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic