Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Call a servlet by an img tag

843841Oct 26 2004 — edited Oct 26 2004
I,ve a little problem.

I need to call a servlet (gif.class) using an img tag.

The servlet is placed in Tomcat5/webapps/Prova/WEB-INF/classes and the HTML page is placed in Tomcat5/webapps/Prova.

Which is the right src in the <img src="">???

And if i want the servlet return not a new html page but the image, what should i write in the doGet method?

I tried to use this servlet
public class gif extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("image/gif");
PrintWriter out=response.getWriter();
out.println("<HTML><BODY>");
out.println("<h1>Ciao<h1>");
out.println("<img src=\"http://127.0.0.1:8080/Prova/px.gif\">");
out.println("</BODY></HTML>");

}

but i call it with a form->submit command and it return a html page.

I need the page load the image using a servlet.
the image(px.gif) is placed in Tomcat5/webapps/Prova.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2004
Added on Oct 26 2004
3 comments
290 views