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

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » JSP » Form Input Data 
23.25.5.Form with Error Checking

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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.