我正在尝试从JSP页面调用Servlet。

index.jsp:

<a href="VisitServlet">Visit</a>

目录结构:
Web Page --> Pages --> HomePage --> index.jsp
Source Packages --> servlets.a.b.VisitServlet.java

web.xml:
<servlet>
    <servlet-name>VisitServlet</servlet-name>
    <servlet-class>servlets.a.b.VisitServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>VisitServlet</servlet-name>
    <url-pattern>/VisitServlet</url-pattern>
</servlet-mapping>

我收到这个错误:
HTTP Status 404 - Not Found

最佳答案

尝试使用:

<a href="${pageContext.request.contextPath}/VisitServlet">Visit</a>

10-06 12:35