开发者

UTFDataFormatException and ClassNotFoundException when adding an image to Liferay portlet

开发者 https://www.devze.com 2023-03-19 15:57 出处:网络
I use Liferay 5.2.3 on Tomcat 5.5. I added the tag <img alt=\"G.png\" src=\"<%= request.getContextPath() %>/images/G.png\">

I use Liferay 5.2.3 on Tomcat 5.5. I added the tag

<img alt="G.png" src="<%= request.getContextPath() %>/images/G.png">

to one of the JSPs that I dispatch my portlet to, and I received:

ERROR [http-8080-Processor22] (StandardWrapperValve.java:253) Servlet.service() for servlet jsp threw exception
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.
        at org.apache.jasper.xmlparser.UTF8Reader.invalidByte(UTF8Reader.java:621)
        at org.apache.jasper.xmlparser.UTF8Reader.read(UTF8Reader.java:492)
        at org.apache.jasper.xmlparser.XMLEncodingDetector.load(XMLEncodingDetector.java:1000)
        at org.apache.jasper.xmlparser.XMLEncodingDetector.skipString(XMLEncodingDetector.java:951)
        at org.apache.jasper.xmlparser.XMLEncodingDetector.scanXMLDecl(XMLEncodingDetector.java:1209)
        at org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:121)
        at org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:109)
        at org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:305)
        at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:170)
        at org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
        at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:156)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Appl开发者_JAVA技巧icationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.header.HeaderFilter.processFilter(HeaderFilter.java:109)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:78)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
        at java.lang.Thread.run(Thread.java:662)

ERROR [http-8080-Processor20] (StandardWrapperValve.java:253) Servlet.service() for servlet jsp threw exception
java.lang.ClassNotFoundException: org.apache.jsp.images.G_png
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:131)
        at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
        at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:597)
        at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:314)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
        at com.liferay.portal.servlet.filters.header.HeaderFilter.processFilter(HeaderFilter.java:109)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
        at com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:78)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
        at java.lang.Thread.run(Thread.java:662)

Some images are loaded well and some are not.

What could be going wrong?


We reference images in our jsp by creating a tag

using the following syntax

<%@ tag isELIgnored="false" body-content="empty" %>${pageContext.request.contextPath}/images/

Stored in a file called imagesPath in /WEB-INF/tags/html then use that in the jsp

<%@ taglib prefix="html" tagdir="/WEB-INF/tags/html" %>




<img src="<html:imagesPath />intro.jpg"  alt="Introduction"/>

I am guessing the important bit of this that you are missing is the pageContext ?

0

精彩评论

暂无评论...
验证码 换一张
取 消