无法从JSP调用servlet

时间:2014-10-01 04:39:05

标签: jsp servlets error-handling

我试图从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

1 个答案:

答案 0 :(得分:2)

尝试使用:

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