• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

include directive not working

 
Tripti Ag
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is <servlet-name> as jsp and <servlet-mapping> as jsp1
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tripti Ag
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem has been resolved. I removed "/" from the path to image. Thanks!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic