如何用 WildFly 显示 JSP

How to display JSP with WildFly

当我使用 JBoss 7.1.1 时,我可以显示一个 JSP 页面来做类似的事情:

@WebServlet("/path")
public class Controller extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.getServletContext().getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response);
    }

}

但是当我用 WildFly 9.0.2 做同样的事情时它不工作并且我有以下错误:

15:55:40,264 DEBUG [org.jboss.resteasy.core.SynchronousDispatcher 60] (default task-2) PathInfo: /WEB-INF/login.jsp
15:55:40,269 WARN  [org.jboss.resteasy.core.ExceptionHandler 135] (default task-2) failed to execute: javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/myapp-web/WEB-INF/login.jsp
    at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:112) [resteasy-jaxrs-3.0.11.Final.jar:]
    at org.jboss.resteasy.core.registry.RootNode.match(RootNode.java:43) [resteasy-jaxrs-3.0.11.Final.jar:]
    at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) [resteasy-jaxrs-3.0.11.Final.jar:]
    ...

我的 web.xml 文件几乎是空的:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
</web-app>

如何使用 WildFly 9 进行操作?

我找到了解决方案。这是我的错误。在下面的 class 中,注释值是 "/" 而不是 "/ws" 例如:

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/ws")
public class JaxRsActivator extends Application {

}

听起来您正在将 client/user 重定向到 restful 服务的登录提示。我看到这样做的方法是使用 web.xml 文件中的 BASIC 身份验证配置。我最近将 dukes-forest 移植到 wildfly 并使用了该设置。欢迎您 look at it if you want. The service is a payment service and it is setup to use a database to hold users. The database configuration is in the entities project, and the client is in the main dukes-store project in the PaymentHandler.java class。希望这有帮助。