2

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.

4

3 回答 3

0

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.

于 2013-05-16T16:22:48.450 回答
0

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).

于 2013-05-21T15:31:02.663 回答
0

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;
    }
于 2016-12-17T15:10:46.933 回答