Using JavaBean for File Upload (5) Application Instances

Source: Internet
Author: User

 

 

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 "));
%>

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.