我有无限循环< jsp:forward page=“/myservlet”/>单击提交输入时

91zkwejq  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(382)

我的jsp页面web/jsppages/addreport.jsp

<%if(request.getParameter("addReport") != null){ %>
<jsp:forward page="/addReportGuiControlServlet" />
<%} %>

<form action="addReport.jsp" name="myform" method="POST">
    <h4 class="desc">How many people are there in the queue?</h4>
    <div>   
        <input class="addreport" type="checkbox" id="isLast" name="isLast">
        <label class="desc">I'm the last of the queue</label>
    </div>
    <div class="container1">
        <input class="addreport" type="text" name="queueLen" id="queueLen" autocomplete="off">
    </div>
    <div class="container2">    
        <input class="addreport" type="submit" name="addReport" value="Add Report">
    </div>
</form>

我的servlet

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
{

    RequestDispatcher rd = request.getRequestDispatcher("/jspPages/addReport.jsp");
    rd.forward(request, response);

}

我的web.xml

<servlet>
    <servlet-name>AddReportGuiControlServlet</servlet-name>
    <servlet-class>logic.boundary.web.controlgrafico.AddReportGuiControlServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>AddReportGuiControlServlet</servlet-name>
    <url-pattern>/addReportGuiControlServlet</url-pattern>
</servlet-mapping>

错误的结果是一个无限循环。我认为问题出在参数“addreport”上,因为在servlet中我试图打印它,结果是!=null,但我不知道如何设置此值。

6ie5vjzr

6ie5vjzr1#

我通过在servlet的url中添加一个参数来解决这个问题:

RequestDispatcher rd = request.getRequestDispatcher("/jspPages/addReport.jsp?forward=true");

然后我将控件插入jsp:

<%if(request.getParameter("addReport") != null){
    //controllo se la pagina è stata già mandata dalla servlet

    if(request.getParameter("forward") == null){
    %>
        <jsp:forward page="/addReportGuiControlServlet"></jsp:forward>
    <%
    }
}
%>

这是因为参数addreport保持不为null,然后由servlet转发

相关问题