2
votes

In our web.xml, we have CXFServlet mapped to the /* url pattern:

<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

This works great and we don't want to change it at this point. But I would like to have an html page (/admin/index.html) that is not handled by the CXFServlet, and is just served up directly as html. How can I accomplish this? I don't know how to create a servlet mapping just to serve an html page.

Note we are using IBM WebSphere 8 (WAS 8) if that matters.

3
Consider welcome-file-list and welcome-fileSotirios Delimanolis
welcome-file does not work; I added a welcome-file of index.html but the CXFServlet still handles requests for /admin and /admin/. It responds with "No service found".Michael Lucas
@MichaelLucas, Yes, you are right. It should be the other way around.Ravi Trivedi

3 Answers

0
votes

You can try:

<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/admin/*</url-pattern>
</servlet-mapping>

It work's in Jetty and Tomcat.

0
votes

None of the given answers (so far) met my requirements, but I found a simple solution that did.

For some reason it turns out that WebSphere will handle JSPs itself, rather than delegating to the servlet that has the /* mapping -- even though there is no specific mapping in web.xml mentioning JSPs. Maybe this is part of the spec and one would have to explicitly map *.jsp to a servlet if you want it to handle those requests?

In any case it works for me -- instead of using /admin/index.html I can use /admin/index.jsp (and will probably add index.jsp to welcome-file-list so that requests for /admin will also give this page).

0
votes

You can have some code in CXFServlet.java

In doget() methods:

URL url = new URL(request.getRequestURL());
    System.out.println("URL is:" + url);
if (url.toString().contains("/admin/")) {
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter pw = response.getWriter();
        pw.print("<!DOCTYPE html><html lang=\"fa\" dir=\"rtl\">\n"
                + "<head>"
                + "<meta charset=\"utf-8\"/>"
                + "</head>"
                + "<body>"
                + "<div>some thing</div>"
                + "<body></html>");
        pw.close();
        return;
    }