Servlet无限循环

时间:2014-10-25 16:57:37

标签: java jsp servlets infinite-loop

我希望你能帮助处理servlet中无限循环的问题。这些问题通常会导致错误的servlet映射(通常是“/ *”)。但在我的情况下,它具有特定的值 - conrete jsp文件的名称。

的Servlet

public class TrainsListServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void processRequest(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    EmployeeService employeeService = new EmployeeServiceImpl();
    List<Train> trains = (List<Train>) employeeService.getTrains();
    request.setAttribute("trains", trains);
    RequestDispatcher dispatcher = getServletContext()
            .getRequestDispatcher("/getTrainsList.jsp");
    dispatcher.forward(request, response);

}

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    processRequest(request, response);
}

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    processRequest(request, response);

}

}

的web.xml:

...
<servlet>
    <servlet-name>TrainsList</servlet-name>
    <display-name>TrainsList</display-name>
    <description></description>
    <servlet-class>ru.tsystems.jsproject.sbb.Servlets.TrainsListServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>TrainsList</servlet-name>
    <url-pattern>/getTrainsList.jsp</url-pattern>
</servlet-mapping>

...

getTrainsList.jsp:

...
    <c:forEach var="train" items="${trains}">
        <tr>
            <td><c:out value="${train.getNumber()}" /></td>
            <td><c:out value="${train.getSeatsCount()}" /></td>
            <td><c:out value="${train.getFrequence()}" /></td>
        </tr>
    </c:forEach>
...

这都会导致processRequest方法无限循环。请帮忙, 告诉我我做错了什么?

1 个答案:

答案 0 :(得分:1)

使用html文件映射

<servlet-name>TrainsList</servlet-name>
<url-pattern>/getTrainsList.html</url-pattern>

然后关注http://localhost:8080/.../getTrainsList.html,您将从Servlet获取响应getTrainsList.jsp