Include Servlet Macro Example



I was looking through some of the marcos, and discovered the include Servlet Marco, which seems like the prefect marco for what I need to do.

However, there is one thing I don’t understand when reading through the extension.

“For this to work a jsp servlet must be correctly declared and configured in XWiki’s web.xml file.”
Is there an example on how to correctly declare and configure the jsp servlet in the web.xml file? If so, where should we place the jsp servlet in our WEB-INF directory?



Hi there. It works by doing the following:

    public String invokeServletAndReturnAsString(String url, XWikiContext xwikiContext)

        HttpServletRequest servletRequest = xwikiContext.getRequest();
        HttpServletResponse servletResponse = xwikiContext.getResponse();

        try {
            return IncludeServletAsString.invokeServletAndReturnAsString(url, servletRequest, servletResponse);
        } catch (Exception e) {
            LOGGER.warn("Exception including url: " + url, e);
            return "Exception including \"" + url + "\", see logs for details.";



This is standard Servlet stuff, not related to XWiki.

Now I’m surprised you’re asking because if you have the need to include a servlet or JSP then it means you know what they are and you know to declare them :slight_smile:

What’s your use case?