*
The moose likes Servlets and the fly likes servlet auto loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet auto loading" Watch "servlet auto loading" New topic
Author

servlet auto loading

Dhanashree Mankar
Ranch Hand

Joined: Aug 25, 2003
Posts: 123
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

Joined: May 29, 2003
Posts: 1258
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?


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Dhanashree Mankar
Ranch Hand

Joined: Aug 25, 2003
Posts: 123
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

Joined: Aug 25, 2003
Posts: 123
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

Joined: May 29, 2003
Posts: 1258
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

Joined: Aug 25, 2003
Posts: 123
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

Joined: Aug 25, 2003
Posts: 123
please help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet auto loading