Include Servlet Macro Example

Hi,

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.";
        }

    }

See xwiki-platform/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/XWiki.java at 5650c9b96217a61508d00de15d27f7a227a48d87 · xwiki/xwiki-platform · GitHub

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?

Thx