Form with Error Checking : Form Input Data « JSP « Java Tutorial






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)








23.25.Form Input Data
23.25.1.Use Loop to Read Form Controls
23.25.2.Use For Each to Loop Through all Values Passed in by Form
23.25.3.Read Hidden Control in Same File
23.25.4.Pass Form Value to Bean
23.25.5.Form with Error Checking