Unable to forward. The answer has already been made. error

I am calling a servlet from jsp using

//My servlet code is: public void doGet(HttpServletRequest request, HttpServletResponse response) { String template="test"; abcViewBean punchOutCan = new abcViewBean(); punchOutCan.setPunchOutCanonicalRes(template); try { request.getRequestDispatcher("/PunchOutCanonicalError.jsp").forward(request,response); } catch (ServletException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

My JSP code is:

 <jsp:include page="/PunchOutCanonicalServlet" flush="true"/> <c:out value="${punchOutCan.punchOutCanonicalRes}" /> 

Please suggest how to get rid of this.

0
source share
1 answer

Exclude (delete) this statement from the doGet servlet because you are importing the response into the JSP.

 request.getRequestDispatcher("/PunchOutCanonicalError.jsp") .forward(request,response); 

doGet should be:

 @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ String template="test"; abcViewBean punchOutCan = new abcViewBean(); punchOutCan.setPunchOutCanonicalRes(template); //You can push the bean object into request via setAttribute //eg //request.setAttribute("punchOutCan",punchOutCan); } 

And the JSP code,

 <jsp:include page="/PunchOutCanonicalServlet" flush="true"/> <c:out value="${punchOutCan.punchOutCanonicalRes}" /> 
+1
source

All Articles