aspose file tools*
The moose likes JSP and the fly likes include directive not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "include directive not working" Watch "include directive not working" New topic
Author

include directive not working

Tripti Ag
Ranch Hand

Joined: Jul 03, 2009
Posts: 37
I have developed a very small JSP code to use include directive

<%@ page contentType="text/html" %>
<%@ include file="/google.jpg" %>

<html>
<head>
<title> JSP Page </title>
</head>

<body>
<br><br><br><br><br><br><br><br>
<h1> Explore the world of Google search </h1>
</body>
</html>


My directory structure is as follows:
c:\program files\Apache Software foundation\tomcat 7.0\webapps\MyJSP
Inside webapps\MyJSP:
WEB-INF
|____web.xml
IncludeJSP.jsp
google.jpg

Web.xml is as follows:
<web-app>
<servlet>
<servlet-name> jsp </servlet-name>
<jsp-file> /IncludeJSP.jsp </jsp-file>
</servlet>

<servlet-mapping>
<servlet-name> jsp1 </servlet-name>
<url-pattern>/IncludeJSP.jsp</url-pattern>
</servlet-mapping>

</web-app>

When I remove include directive, code is running properly. After including directive, I am getting error as:
HTTP Status 500 - /IncludeJSP.jsp (line: 2, column: 1) Invalid byte 1 of 1-byte UTF-8 sequence.
type Exception report

message /IncludeJSP.jsp (line: 2, column: 1) Invalid byte 1 of 1-byte UTF-8 sequence.

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: /IncludeJSP.jsp (line: 2, column: 1) Invalid byte 1 of 1-byte UTF-8 sequence.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:324)
org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:357)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:467)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1779)
org.apache.jasper.compiler.Parser.parse(Parser.java:135)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:119)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:193)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)


Kumar Khiani
Ranch Hand

Joined: Aug 24, 2013
Posts: 40

Why is <servlet-name> as jsp and <servlet-mapping> as jsp1


Oracle Certified SQL Expert
OCEWCD 6, OCPJP 7, OCAJP 7
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

You're trying to include a JPEG image? :shock:

Of course that won't work. The file needs to be a text file containing a JSP fragment.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tripti Ag
Ranch Hand

Joined: Jul 03, 2009
Posts: 37
Thanks for giving so much stress on my mistake. I will remember this mistake throughout my life :-).
Now I have created a separate jsp file which is as follows
<html>
<head></head>
<body>
<img src="\google.jpg"><br>
</body>
</html>
I have saved the file in MyJSP folder. Now problem is image is not visible . I think its related to path.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

Yes, the URL for the image is not valid. First of all "\" is not valid in a URL path. Secondly, the URL should be a server-relative path to the image file. See the JspFaq and ServletsFaq for more info.

It also not valid to include a full HTML file into another. Why is your inlude file a full HTML page if it's only a fragment to be included?
Tripti Ag
Ranch Hand

Joined: Jul 03, 2009
Posts: 37
Problem has been resolved. I removed "/" from the path to image. Thanks!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: include directive not working