index.jsp
<HTML>
<HEAD><TITLE>Implicit Object Project</TITLE></HEAD>
<BODY>
<FORM METHOD="POST" ACTION="StreamResponse.jsp">
<H2> Streaming file demo </H2>
<TABLE>
<TR>
<TD> Enter File name: </TD>
<TD> <INPUT TYPE="text" SIZE=60 NAME="File"> </TD>
</TR>
<TR>
<TD> Enter optional MIME type: </TD>
<TD> <INPUT TYPE="text" SIZE=30 NAME="MIME type"> </TD>
</TR>
</TABLE>
<P>
<INPUT TYPE=submit VALUE="Fetch">
<INPUT TYPE=reset VALUE="Reset">
</FORM>
</BODY>
StreamResponse.jsp
<%@ page isErrorPage="true" %>
<H3> Error occured: <%= exception.getMessage() %> </H3>
<%@ page import="java.io.*" errorPage="StreamError.jsp" %>
<%
String filename = request.getParameter("File");
String mime_type = request.getParameter("MIME type");
%>
<%
if((mime_type != null) && (mime_type.length() > 0)) {
response.setHeader("Content-Type", mime_type);
}
%>
<%
String line = null;
BufferedReader iread = new BufferedReader(new FileReader(filename));
while((line = iread.readLine()) != null) {
out.write(line);
}
iread.close();
%>
Download: JSPFormWithErrorChecking.zip( 4 k)