At 11:19 AM 3/1/99 +0100, you wrote:
>servletrunner doesn't serve html-files. so you can't use servletrunner
>with a html-page with an embedded applet. you could change the applet
>that it behaves like a normal java-application. the java-application can
>then access the servlet which is running on servletrunner.
>
It's actually quite easy to modify servletrunner to serve whatever type of
files you like. I made a quick simpleminded modification to the one I'm
using to serve html, gif, and jpeg files but you could add code to support
external Javascript or anything else you like.
I don't know the legalities of distributing modified versions of Sun's
software so I'm not going to do that. I will tell you what I did and you
can modify your own if you care to. Note - this is for JSDK 2.0, I haven't
looked at 2.1.
1. In directory ..../JDSK2.0/lib/src/sun/servlet/http locate module
HttpServerHandler.class.
2. Decompile this module. I used JAD:
http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
3. Locate the following line:
httpresponse.sendError(403, "Will not serve files, only servlets");
4. Replace it with your code, mine is:
//httpresponse.sendError(403, "Will not serve files, only servlets");
String s = messagebytes.toString();
try
{
File f = new File(".." + s);
String content = "text/plain";
if (s.endsWith("htm") || s.endsWith("html"))
content = "text/html";
else
{
if (s.endsWith("gif"))
content = "image/gif";
else
{
if (s.endsWith("jpg") || s.endsWith("jpeg"))
content = "image/jpeg";
}
}
httpresponse.setContentType(content);
//System.out.println("File " + s + " length is: " + f.length());
//httpresponse.setContentLength((int) f.length());
httpresponse.unsetContentLength();
InputStream in = new FileInputStream(f);
OutputStream out = httpresponse.getOutputStream();
int len;
byte[] buf = new byte[1024];
while (true)
{
len = in.read(buf);
if (len < 1)
break;
out.write(buf, 0, len);
}
}
catch (Exception e)
{
e.printStackTrace();
httpresponse.sendError(403, "File not found " + s);
}
5. Compile this file and rebuild your jsdk.jar in ..../JSDK2.0/lib
This modification assumes that the files to be served are at or in a
directory at the same level as the servlet directory and that the file
references are relative to the servlet directory. For example if you have
the following directory structure:
sr_root
html
images
servlet
Then the URL of an image file might be ../images/mypic.gif.
Regards,
Bob
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html