I am reading the book "Head First Servlet and JSP". There is one question I cannot fully understand.
I am not sure why the book says that "it is not possible to import the contents of any binary file into a jsp page, which generates a HTML content".
Why the above statement is true?
Is it due to run time include a binary file will open a new input stream?
What exception will this cause?
Does this mean even if I use <%@ include file = "logo.png" @>
to include binary file at compilation time rather than run time, the include will still fail?
CodePudding user response:
After testing
<jsp:include page="banner.png"></jsp:include>
results in untranslated codes
² /;ÖXÈ%Ïa€wñÉšª1rÂ<š›AÃrðÖŠf’²dPíDuS3=wÄ RiTêÔjO‡²qç™Ûþ”àÕ$'ûv3(YÛ¹ÏÙ&ÜzíuĽþãzŠÛþq=2ÒI_e•5Gä܆àdKÜËÇ 7Ž>â¶s\ŒtÒKÙ×¾ö·vëDæò}û÷ÿdýSžsÅmϸéd¾²¯þå_ÙgÐù 6?ó…ÂSÇ•#¿¡Eg»ÅõÈH's”½cYsDùÇÁóÁÂôʧóÖ›o…ß4v‹ëi´¦)
!È VVVX±åݒ𘇶/âb/žXº…i›YYj:ʇ¼ÛØ„eâùóçYûæÛ,6 ¢¬iüdàäÉ“¢Ý˜ú^X;»L@®HN`³yxS¨¨®X²ûS¨Á˜×µlm u(fóKæÔQJÅ,es îõ‡nþ‹}
<%@ include file = "banner.png" %>
results in 500 server error
HTTP Error Code: 500
Error Message:
/Login.jsp(44,56) java.io.UTFDataFormatException: JSPG0287E: Invalid byte 1 of 1-byte UTF-8 sequence.
Root Cause:
com.ibm.ws.jsp.JspCoreException: /Login.jsp(44,56) java.io.UTFDataFormatException: JSPG0287E: Invalid byte 1 of 1-byte UTF-8 sequence.
at com.ibm.ws.jsp.translator.document.Jsp2Dom.getJspDocumentAsJspPage(Jsp2Dom.java:529)
at com.ibm.ws.jsp.translator.document.Jsp2Dom.getJspDocument(Jsp2Dom.java:196)
at com.ibm.ws.jsp.translator.JspTranslator.<init>(JspTranslator.java:73)
at com.ibm.ws.jsp.translator.JspTranslatorFactory.createTranslator(JspTranslatorFactory.java:116)
at com.ibm.ws.jsp.translator.utils.JspTranslatorUtil.translateJsp(JspTranslatorUtil.java:262)
at com.ibm.ws.jsp.translator.utils.JspTranslatorUtil.translateJspAndCompile(JspTranslatorUtil.java:123)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.translateJsp(AbstractJSPExtensionServletWrapper.java:560)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper._checkForTranslation(AbstractJSPExtensionServletWrapper.java:477)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.checkForTranslation(AbstractJSPExtensionServletWrapper.java:298)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:167)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)