Hi, i am following the Orelliey publication for javaservlet .in that image should be taken from the URL. the code is like this public class imgoverriding extends HttpServlet { Frame f1=null; Graphics g=null; public void init(ServletConfig con) throws ServletException { super.init(con); f1=new Frame(); f1.addNotify();
Image img=Toolkit.getDefaultToolkit().getImage(source); MediaTracker mt=new MediaTracker(f1); try{ mt.waitForAll(); } catch(InterruptedException e) { getServletContext().log(e,"interrupted during the image downloading");
} int w=img.getWidth(f1); int h=img.getHeight(f1); Image img1=f1.createImage(w,h); g=img1.getGraphics(); g.drawImage(img,0,0,f1); g.setFont(new Font("Monospaced",Font.ITALIC,30)); g.drawString("Neelima",0,0); GifEncoder encoder = new GifEncoder(img1, out); // GifEnCoder gif2=new GifEncoder(img1,out); encoder.encode(); } finally { if(g!=null) g.dispose(); if(f1!=null) f1.removeNotify(); } } } the image is taken throgh the method req.getPathTranslated().image is in my localsystem.how to send that image to getPathTranslated(). thanks in advance, Neelima
R K Singh
Ranch Hand
Joined: Oct 15, 2001
Posts: 5369
posted
0
Its always good practise to write your code inside code tag like..
I agree, font size sucks but still its better than losing your formatting. Though I dont know anything abt Image class but I am just guessing that your image file should be in the same folder where your servlet is residing and then you should append your image file name to source. Something like this should work.. source = source + "/" + "imageFileName.gif" ; This should be done before this statement Image img=Toolkit.getDefaultToolkit().getImage(source); I think best place will be in the else block of this
HTH try and tell the result
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Originally posted by Ravish Kumar: Though I dont know anything abt Image class but I am just guessing that your image file should be in the same folder where your servlet is residing and then you should append your image file name to source. Something like this should work.. source = source + "/" + "imageFileName.gif" ;
I disagree. Placing the image in the same folder as the servlet is no guarantee of anything. My prefernce for finding resources associated with web applications is to make the resource available on the web app classpath and use the web app ClassLoader to find it. This way it is not file system dependent and is therefore portable. Place the image in the web-inf/classes directory and try
Dave
R K Singh
Ranch Hand
Joined: Oct 15, 2001
Posts: 5369
posted
0
Originally posted by David O'Meara: [QB]I disagree. Placing the image in the same folder as the servlet is no guarantee of anything.
I agree with you. I said this with ref to the given code. This was the easist way to load the image with the given code where one wants to make use of req.getPathTranslated();