Servlet错误的响应

时间:2016-07-01 08:02:13

标签: java xml servlets web-applications

我的网络应用程序中有3个servlet。

第一个servlet正常工作。 从第一个servlet复制的第二个和第三个servlet不起作用,也没有响应。

但是,我在互联网上搜索,所有网站都说:the error in web.xml file

这是我的web.xml文件:

  <?xml version="1.0" encoding="UTF-8"?>
  <web-app version="3.1">
<servlet>
    <servlet-name>getmarks</servlet-name>
    <servlet-class>getmarks</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Login</servlet-name>
    <servlet-class>Login</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Enter</servlet-name>
    <servlet-class>Enter</servlet-class>
    <load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>getmarks</servlet-name>
    <url-pattern>/getmarks</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Login</servlet-name>
    <url-pattern>/Login</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Enter</servlet-name>
    <url-pattern>/Enter</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

2 个答案:

答案 0 :(得分:0)

您应该在<servlet-class>代码中添加完整的班级名称。

此外,<web-app>标记缺少有关XML Schema的一些属性。您可以找到更多信息here

对于3.1版,它应该如下所示:

<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_3_1.xsd"
         version="3.1">

// your mappings 

</web-app>

也缺少关闭</web-app>标记。

答案 1 :(得分:0)

    Try This Code Web.xml file 



<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
      <display-name>Your Project Name</display-name>
    <servlet>
        <servlet-name>ABC</servlet-name>
        <servlet-class>getmarks</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>DEF</servlet-name>
        <servlet-class>Login</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>GHI</servlet-name>
        <servlet-class>Enter</servlet-class>
        <load-on-startup>3</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>ABC</servlet-name>
        <url-pattern>/getmarks_1</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>DEF</servlet-name>
        <url-pattern>/Login_1</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>GHI</servlet-name>
        <url-pattern>/Enter_1</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    </web-app>