Inclusion of servlet in a jsp

Posted on 2005-04-12
Last Modified: 2008-03-17
I have a servlet named ""

       It contains the fiollowing lines of code

public class chartServlet extends HttpServlet {

     * Process a GET request.
     * @param request  the request.
     * @param response  the response.
     * @throws ServletException if there is a servlet related problem.
     * @throws IOException if there is an I/O problem.
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
                GeneralUtility chartUtil =  GeneralUtility.getInstance();
             BufferedImage pieChart3D = chartUtil.createPieChart();                              
          OutputStream out = response.getOutputStream();

I need to include this chartServlet in my jsp inorder to display the piechart to the user.
Could anyone pls help me out in this context?
Question by:ramsharma23
    LVL 92

    Accepted Solution

    specify the path to your servlet as the src attribute for you img tag

    <img src="\servlet\ChartServet">
    LVL 29

    Assisted Solution

    Objects is correct that you should just use the image tag to generate the jpeg via the servlet.

    A couple of points though. Make sure that your servlet is in a package as some servlet containers will cause you unnecessary problems if you don't have a package declaration.

    package  ramsharma23;
    public class chartServlet extends HttpServlet {

    This means that the class file for this example would be found in <webapp>WEB-INF/classes/ramsharma23/chartServlet .class

    Also, never use the invoker servlet to access your servlets (for lots of reasons) but make sure that they are mapped in the web.xml file. When you do this, it's also common practise to add the suffix ".do" to signify that it's a servlet in the url you map to.

            <servlet-class>ramsharma23.chartServlet </servlet-class>


    So objects img tag becomes <img src="/"> as specified in the url-pattern tag above.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
    DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now