用于调用Servlet的Image Src [英] Image Src for calling a Servlet

查看:174
本文介绍了用于调用Servlet的Image Src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从img src调用一个Servlet。我已经定义了一个名为ImageProducerServlet的Servlet类,并在web.xml中注册了它:

I want to call a Servlet from img src. I have defined a Servlet class with name ImageProducerServlet and registered it in web.xml:

<servlet>
   <servlet-name>ImageProducerServlet</servlet-name>
   <servlet-class>com.company.servlet.ImageProducerServlet</servlet-class>    
</servlet>
<servlet-mapping>
   <servlet-name>ImageProducerServlet</servlet-name>
   <url-pattern>/imageproducerservlet</url-pattern>
</servlet-mapping>

在这个servlet的doGet中我刚写了一个 System.out 。现在从JSF页面我将servlet称为:

In this servlet's doGet I just wrote a System.out. Now From the JSF page I am calling that servlet as:

<img src="/imageProducerServlet" id="id"/>

我原以为它会打印System.out!但它没有。

I was expecting that it would print the System.out! But it doesn't.

添加img的页面的URL是:

The URL for the page where the img is added is:


http:// localhost:7101 / mycompany / faces / home

如果我在地址栏中写下以下网址:

If I write in the address bar the follwoing URL:


http:// localhost:7101 / mycompany / imageproducerservlet

然后按回车键,然后servlet的doGet正在执行。

and press enter then the servlet's doGet is executing.

我无法找到它的解决方案。

I am unable to find it's solution.

如果我得到您的建议,将会非常有帮助。

It will be very helpful if I get your suggestions.

谢谢和问候。

推荐答案

如果这样做:

http://localhost:7101/mycompany/imageproducerservlet

然后你需要你的img标签看起来像这样:

then you need your img tag to look like that:

<img src="/mycompany/imageProducerServlet" id="id"/>

这篇关于用于调用Servlet的Image Src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆