List Denizens:
I'm having trouble displaying an image via HTML generated from a
servlet running in JBoss/Jetty. I can display the image OK if it's
from a JSP but not (so far) from a servlet. In the case of the
servlet, the alt text appears. My guess is it's a configuration
problem, but I don't know what to do to change the configuration.
Situation:
JBoss/Jetty 3.0.
WAR file nozama.war deploys successfully on JBoss.
When servlet is run, the following exception appears on the log:
09:30:46,458 INFO [Jetty] nozama.servlets.HelloServlet: init
09:30:46,465 INFO [Jetty] Dynamic load 'nozama.servlets.HelloServlet' at
/servlet/nozama.servlets.HelloServlet
09:30:46,944 WARN [Jetty] WARNING:
java.lang.ClassNotFoundException: image.jpg
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at org.mortbay.http.ContextLoader.loadClass(ContextLoader.java:228)
. . .
This gives the appearance that Jetty is interpreting the image name as
a Java class rather than a JPEG. What must I do in order to make it
load an image rather than try to load a class?
nozama.war:
META-INF/
META-INF/MANIFEST.MF
image.jpg
index.jsp
WEB-INF/
WEB-INF/application.xml
WEB-INF/classes/
WEB-INF/classes/nozama/
WEB-INF/classes/nozama/servlets/
WEB-INF/classes/nozama/servlets/ImageServlet.class
WEB-INF/web.xml
index.jsp: (which works)
<html>
<head><title>JSP!</title></head>
<body>
Hello World!
<br>
<img src="image.jpg" width="300" height="300">
</body>
</html>
ImageServlet.java: (which fails to display the image)
package nozama.servlets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class HelloServlet extends HttpServlet {
protected void service(
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter writer = response.getWriter();
response.setContentType( "text/html" );
writer.println( "<html>");
writer.println( "<head><title>Servlet!</title></head>");
writer.print( "<body\">");
writer.println( "<H1>Hello world -- here's an image!</H1>" );
writer.print( "<img src=\"image.jpg\"");
writer.print( " alt=\"image didn't appear\"");
writer.println( " width=\"300\" height=\"298\">");
writer.println( "</body>");
writer.println( "</html>");
}
}
Generated HTML from servlet (viewed on browser):
<html>
<head><title>Servlet!</title></head>
<body><h1>Hello world -- here's an image!</h1>
<img src="image.jpg" alt="image didn't appear" width="300" height="298">
</body>
</html>
application.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<application>
<display-name>Nozama</display-name>
<module>
<web>
<web-uri>nozama.war</web-uri>
<context-root>/nozama</context-root>
</web>
</module>
</application>
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________