Application Instance
CompiledBean, we can use it from the Servlet or JSP page. You may use beans in Servlet/JSP environments such as Tomcat. The simplest way to deploy beans is to compress the class file into a jar file, but put the jar file in the lib directory of Tomcat. To mount Tomcat to the jar file, you must restart Tomcat.
The following is an HTML file and a JSP file. They demonstrate the Bean application. The HTML file contains a form and several input elements:
<Html>
<Head>
<Title> File Upload </title>
</Head>
<Body>
<Form action = jsp1.jsp enctype = "MULTIPART/FORM-DATA" method = post>
Author: <input type = text name = author>
<Br>
Company: <input type = text name = company>
<Br>
Note: <textarea name = comment> </textarea>
<Br>
Select the file to be uploaded <input type = file name = filename>
<Br>
File description: <input type = text name = description>
<Br>
<Input type = submit value = "Upload">
</Form>
</Body>
</Html>
After you submit the preceding form, the HTTP request is processed by Jsp1.jsp. Jsp1.jsp uses the FileUpload Bean to process requests. The Jsp1.jsp code is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<Jsp: useBean id = "TheBean" scope = "page"
Class = "com. brainysoftware. web. FileUploadBean"/>
<%
TheBean. doUpload (request );
Out. println ("Filename:" + TheBean. getFilename ());
Out. println ("<BR> content type:" + TheBean. getContentType ());
Out. println ("<BR> Author:" + TheBean. getFieldValue ("Author "));
Out. println ("<BR> Company:" + TheBean. getFieldValue ("Company "));
Out. println ("<BR> note:" + TheBean. getFieldValue ("Comment "));
%>