Glassfish JavaEE目录设置-404错误

时间:2019-05-27 03:53:14

标签: java servlets intellij-idea glassfish

在使用IntelliJ在Glassfish上部署Java EE应用程序时,我的servlet应该放在哪里?截至目前,我的目录如下

web ---
       |
       WEB-INF---
                 |
                 classes---
                           |
                            java

但是,这会产生404错误。我将WebServlet批注与urlpattern / login 一起使用,但是我无法使用URL localhost:8080/mywarname/login

进入servlet。

如果我将servlets放在src文件夹中(这是IntelliJ教程建议的-与 / web 位于同一目录中),我仍然会遇到 404错误

Servlet注释

@WebServlet(name = "java.LoginServlet", urlPatterns = {"/login"})
public class LoginServlet extends HttpServlet {

.iml文件

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="FacetManager">
    <facet type="web" name="Web">
      <configuration>
        <descriptors>
          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
        </descriptors>
        <webroots>
          <root url="file://$MODULE_DIR$/web" relative="/" />
        </webroots>
      </configuration>
    </facet>
  </component>
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" scope="PROVIDED" name="GlassFish 5.0.0" level="application_server_libraries" />
    <orderEntry type="library" scope="PROVIDED" name="GlassFish 5.0.0 - RESTful Web Service" level="application_server_libraries" />
  </component>
</module>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
</web-app>

0 个答案:

没有答案