我正在使用jsp调用servlet
//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();
}
}
我的JSP代码是:
<jsp:include page="/PunchOutCanonicalServlet" flush="true"/>
<c:out value="${punchOutCan.punchOutCanonicalRes}" />
请建议,如何摆脱这个。
答案 0 :(得分:1)
从servlet的doGet
中排除(删除)此语句,因为您正在JSP中导入响应。
request.getRequestDispatcher("/PunchOutCanonicalError.jsp")
.forward(request,response);
doGet必须是:
@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
//e.g
//request.setAttribute("punchOutCan",punchOutCan);
}
和JSP Code,
<jsp:include page="/PunchOutCanonicalServlet" flush="true"/>
<c:out value="${punchOutCan.punchOutCanonicalRes}" />