Save Form Input to File using JSP : File Save Load « JSP « Java Tutorial






index.jsp

<HTML>
    <HEAD>
        <TITLE>Please Sign My Guest Book!</TITLE>
    </HEAD>

    <BODY>
        <CENTER>
            <H1>Please Sign My Guest Book!</H1>
            <FORM ACTION="basic.jsp" METHOD="POST">
                Your name:
                <INPUT TYPE="TEXT" NAME="TEXT1">
                <BR>
                <BR>
                <BR>
                Your comments:
                <BR>
                <TEXTAREA NAME="TEXTAREA1" ROWS="5" COLS="50"></TEXTAREA>
                <BR>
                <INPUT TYPE="SUBMIT" VALUE="Submit"><INPUT TYPE="RESET" VALUE="Reset">
            </FORM>
        </CENTER>
    </BODY>
</HTML>

basic.jsp

<%@ page import="java.io.*" %>
<HTML>
    <HEAD>
        <TITLE>Thanks for Adding to the Guest Book!</TITLE>
    </HEAD>

    <BODY>
        <H1>Thanks for Adding to the Guest Book!</H1>
        Here's what you and others have said:
        <BR>
        <BR>
        <%
            String name = request.getParameter("TEXT1");
            String text = request.getParameter("TEXTAREA1");
            String file = application.getRealPath("/") + "test.txt";
    
            FileWriter filewriter = new FileWriter(file, true);
            filewriter.write("<B>Name: </B>" + name + "<BR>");
            filewriter.write("<B>Comments: </B><BR>");
            filewriter.write(text + "<BR><BR>");
            filewriter.close();
        %>
        <jsp:include page="ch15_04.txt" flush="true"/>
    </BODY>
</HTML>
  Download:  JSPSaveFormInputToFile.zip( 2 k)








23.51.File Save Load
23.51.1.Save Form Input to File using JSP
23.51.2.Index of Files
23.51.3.Read file
23.51.4.Writing Binary Data
23.51.5.Reading Binary Data