Here is the question for Q22 of the final Mock Exam:
Given that /segment/footer.html is a static page, which JSP code would you use to include static content in a JSP?
A. <%@ include file="/segment/footer.html" %>
B. <jsp:forward page="/segment/footer.html" />
C. <jsp:include page="/segment/footer.html"/>
D. RequestDispatcher dispatcher=request.getRequestDispatcher("/segments/footer.html");
The answers given are A and C. I understand why A and C are right. But my question is why D is not right? I want to know the exact reason. Is it because they should be inside <% %>? Or because HTML files can not be the argument of getRequestDispatcher()? (I tried it and it didn't work, but I don't understand because the document says it can include html files, jsp files and Servlets.) Thank you.
Originally posted by Xiaoxiao Lam:
but when I tried it using the exact code as choice D, it didn't work. I changed the file "footer.html" to "footer.jsp", it worked.
Thats interesting, might be .html is considered static page and cannot be used using RequestDispatcher. Please confirm whether you have a .html page or .jsp in the correct location. If its working only with .jsp extension then I guess using RequestDispatcher we cannot include or forward to a static page. I would like to know the result too.
I am wrong. API says
it includes the contect of a HTML file too. So make sure you have a .html file
Yes, I had html file there when I used html file path and it didn't work. When I changed the html file to be a jsp file and used jsp file path, it worked.
Error Message when I used html file:
org.apache.jasper.JasperException: getOutputStream() has already been called for this response
[ March 14, 2006: Message edited by: Xiaoxiao Lam ]