【问题标题】:WildFly 9 deploying simple webapp but 404WildFly 9 部署简单的 webapp 但 404
【发布时间】:2017-05-11 03:37:52
【问题描述】:

我有一个简单的 hello world webapp,当我在 tomcat 中使用 url http://localhost:8080/na/environment 运行它时工作正常; Wildfly 9 中的相同战争不起作用,我收到 404 错误。

谷歌搜索我发现一个 WildFly 项目需要 2 个文件(beans.xml 和 jboss-web.xml),我刚刚添加到项目中但仍然无法正常工作。

我的 wildldFly 管理控制台显示战争已部署并启用

这是我项目的结构:

而我的文件jboss-web.xml的内容是:

<?xml version="1.0" encoding="UTF-8"?>
 <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
  <context-root>/</context-root>
 </jboss-web>

beans.xml 是空的(仍然不知道它的海豚是什么)。

最后,我的 servlet(也是唯一的类)的代码是:

@WebServlet(urlPatterns="/environment")
public class Environment extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response) throws ServletException,
                                                       IOException {
    response.getWriter().append("Hello");
    }

    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException,
                                                        IOException {
    doGet(request, response);
    }



}

我尝试使用:

http://localhost:9990/na/environment/
http://localhost:9990/na.war/environment/
http://localhost:9990/environment/

【问题讨论】:

    标签: web-applications wildfly-9


    【解决方案1】:

    如果您希望上下文为 na,您需要更改您的 jboss-web.xml 以使用 na 作为根上下文。

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
        <context-root>/na</context-root>
    </jboss-web>   
    

    如果您在部署时更改运行时名称,这也应该可以工作。您也可以在 pom 中覆盖 &lt;finalName&gt;na&lt;/finalName&gt;

    【讨论】:

      猜你喜欢
      • 2015-04-02
      • 2018-08-18
      • 2015-08-05
      • 2016-07-12
      • 2014-02-27
      • 1970-01-01
      • 2018-03-09
      • 2018-07-26
      • 2016-11-08
      相关资源
      最近更新 更多