Sure. You can just read in the file and output it to the output stream.
Something like (note this is written on the fly, so caveat emptor):
public class FileServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpSerlvetResponse resp)
{
// Set content type to be regular old HTML
resp.setContentType("text/html");
// Read in file into buffer
FileInputStream fis = new FileInputStream("static.html");
byte[] buf = new byte[fis.available()];
fis.read(buf);
fis.close();
// Write it out to output
resp.getOutputStream().write(buf);
}
}
I've left out all the exception and error handling. Also, you should
customize this to use a file that's passed in through the URL request.
Isn't this is how the Java Web Server loads static HTML requests?
--John Ellithorpe
[EMAIL PROTECTED]
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> Gullanki, Madhu
> Sent: Friday, February 26, 1999 2:33 PM
> To: [EMAIL PROTECTED]
> Subject: posting html page
>
>
> Is it possible to post a static html page from a servlet? If yes, how?
>
> -
> MG
>
> ___________________________________________________________________________
> 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
>
___________________________________________________________________________
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