This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Implement a WebFigure

This example implements a WebFigure. It deploys the WebFigure service and the page that has the WebFigure embedded in it on a single server. This configuration allows you to quickly reference your WebFigure from a JSP page with minimal configuration.

  1. Configure the web server.

    • Install the MATLAB® Runtime in a location where it is accessible to the web server.

    • Add matlabroot\toolbox\javabuilder\jar\javabuilder.jar to the classpath of the web server.


      This file uses native resources. It is critical that it exist in your Web server's class PATH only once. Embedding this file into Web applications causes errors.

  2. Verify that your web server is properly configured by deploying the WebFigureQuickStart application.

    1. Deploy matlabroot\toolbox\javabuilder\jar\WebFigureQuickStart.war to your web server.

    2. Open http://hostName:portNumber/WebFigureQuickStart/WebFigureExample.jsp in a web browser.

      The following default figure page appears:

    3. Click and drag to manipulate the figure.

      For example, to zoom in the figure, click the magnifying glass icon, then hover over the figure.


    Once you have verified that your web server is properly configured you can undeploy the default WebFigure.

  3. Compile the getPlot function as a Java® package.

    function df = getPlot()
      f = figure('Visible','off');
      x = -2:0.25:2;
      [X,Y] = meshgrid(x);
      Z = X.*exp(-X.^2-Y.^2);
      df = webfigure(f);
  4. Create a web application containing the jar file generated by MATLAB Compiler SDK™ and a JSP file to display the figure.

    The generated jar file should be placed in the WEB-INF\lib folder of the web application. The JSP file should be in the root folder of the web application.

  5. Open the WEB-INF\web.xml file and add the reference to WebFigureServlet.

  6. Copy MATLABROOT/toolbox/javabuilder/webfigures/webfigures.tld, the WebFigures customer tag handler file, to the WEB-INF folder of your web application.

  7. In the JSP file, add a reference to the WebFigure tag by including the following line of code at the beginning of the file.

    <%@ taglib 
  8. In the JSP file, add a reference to the package you created using MATLAB Compiler SDK.

    <%@ page import="getPlot.Class1" %>
  9. In the JSP file, add references to the MATLAB Compiler SDK packages that implement WebFigures.

    <%@ page import="com.mathworks.toolbox.javabuilder.webfigures.WebFigure" %>
    <%@ page import="com.mathworks.toolbox.javabuilder.*" %>
  10. In the JSP file, add code to instantiate the deployed class.

    <%! Class1 myDeployedComponent; %>
       public void jspInit()
           try {
        	    //Instantiate the Deployed Component
                myDeployedComponent = new Class1();
           } catch (Exception e)
       public void jspDestroy()
            if (myDeployedComponent!=null)
            myDeployedComponent = null;
  11. Return the WebFigure and attach it to tag for display.

        if (myDeployedComponent!=null)
              // Get the WebFigure from your function's output
       	      WebFigure webFigure = (WebFigure)
              // set it to the tag
                request.getSession().setAttribute("MyFigure", webFigure);
            } catch(ClassCastException e)
                throw new Exception("Issue casting deployed components outputs to WebFigure",
            } catch (Exception e)
       } else {
            out.println("no go");
    <wf:web-figure name="MyFigure" scope="session"/>
  12. Run your application.

    Your custom WebFigure appears:

Was this topic helpful?