需要在tomcat

时间:2016-06-25 20:16:06

标签: java tomcat servlets

我已尝试过其他答案中提到的先前方法,但仍然http://localhost:8080/InterConnect/显示404错误。 而http://localhost:8080/InterConnect/servlet/HomePageServlet页面运行顺利。

  

web.xml文件: -

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<!-- Define servlets that are included in the example application -->

<welcome-file-list>
    <welcome-file>HomePageServlet</welcome-file>
</welcome-file-list>


<servlet>
    <servlet-name>SignInServlet</servlet-name>
    <servlet-class>SignInServlet</servlet-class>
</servlet>

<servlet>
    <servlet-name>SignUpServlet</servlet-name>
    <servlet-class>SignUpServlet</servlet-class>
</servlet>

 <servlet>
    <servlet-name>HomePageServlet</servlet-name>
    <servlet-class>HomePageServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>SignInServlet</servlet-name>
    <url-pattern>/servlet/SignInServlet</url-pattern>
</servlet-mapping>

<servlet-mapping>
   <servlet-name>SignUpServlet</servlet-name>
   <url-pattern>/servlet/SignUpServlet</url-pattern>
</servlet-mapping>

<servlet-mapping>
   <servlet-name>HomePageServlet</servlet-name>
   <url-pattern>/servlet/HomePageServlet</url-pattern>
</servlet-mapping>

1 个答案:

答案 0 :(得分:1)

当浏览器请求http://localhost:8080/InterConnect/时,假设InterConnect是上下文路径,并且假定您已声明<welcome-file>HomePageServlet</welcome-file>,则servlet容器将查看是否存在{{{ 1}}。

您没有/HomePageServlet的映射,只有/HomePageServlet的映射,因此Web服务器返回404(未找到)。

尝试/servlet/HomePageServlet查看是否有效,或将servlet映射更改为<welcome-file>servlet/HomePageServlet</welcome-file>