1 / 19

CS320 Web and Internet Programming Some Loose Ends

Learn how to implement file upload functionality in web applications, including homework submission, file attachments in emails, user profile photos in forums, and online file management.

henriettah
Download Presentation

CS320 Web and Internet Programming Some Loose Ends

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS320 Web and Internet ProgrammingSome Loose Ends Chengyu Sun California State University, Los Angeles

  2. File Upload in Web Applications • Homework submission in CSNS • File attachments in GMail • User profile photo in web forums • Online video, picture, file management applications …

  3. File Upload – The Form <form action="FileUploadHandler" method="post" enctype="multipart/form-data"> First file: <input type="file" name="file1" /> <br /> Second file: <input type="file" name="file2" /> <br /> <input type="submit" name="upload" value="Upload" /> </form>

  4. File Upload – The Request POST / HTTP/1.1 Host: cs.calstatela.edu:4040 […] Cookie: SITESERVER=ID=289f7e73912343a2d7d1e6e44f931195 Content-Type: multipart/form-data; boundary=---------------------------146043902153 Content-Length: 509 -----------------------------146043902153 Content-Disposition: form-data; name="file1"; filename="test.txt" Content-Type: text/plain this is a test file. -----------------------------146043902153 Content-Disposition: form-data; name="file2"; filename="test2.txt.gz" Content-Type: application/x-gzip ?????????UC

  5. Apache commons-fileupload http://jakarta.apache.org/commons/fileupload/using.html FileItemFactory fileItemFactory = DiskFileItemFactory(); ServletFileUpload fileUpload = new ServletFileUpload( fileItemFactory ); List<FileItem> items = (List<FileItem>) fileUpload.parseRequest( req ); for( FileItem item : items ) { if( ! item.isFormFiled() ) { fileItem.write( file ); } }

  6. Example: File Upload • Upload a file and save it to disk • Use absolute path • Use relative path • Handle regular (i.e. non-file) form fields • Save uploaded files to database • http://dev.mysql.com/doc/refman/5.5/en/storage-requirements.html

  7. Store Uploaded Files On disk In database BLOB, CLOB/TEXT BINARY VARCAR, VARCHAR Pros and Cons??

  8. Email in Web Applications • Recover account information • Various notifications, reminders, news letters …

  9. How Email Works • Email address • user@domain, e.g. csun@calstatela.edu • user@host, e.g. csun@exchange.calstatela.edu ?? User A User B

  10. Email Client and Outgoing Email Server • Email client • E.g. Outlook, Thunderbird, web-based like GMail • Outgoing Server Outgoing Server Email Client User A User B

  11. Incoming Server and DNS • Incoming Server • Locating the incoming server – DNS lookup Outgoing Server Incoming Server Email Client User A User B

  12. Receiving Email • An email client retrieves the emails from the incoming email server Outgoing Server Incoming Server Email Client Email Client User A User B

  13. Email Protocols • Simple Mail Transfer Protocol • Internet Message Access Protocol • Post Office Protocol Outgoing Server Incoming Server SMTP IMAP/POP SMTP Email Client Email Client User A User B

  14. Set up Email Servers in Outlook

  15. JavaMail http://www.oracle.com/technetwork/java/javamail/index.html / Properties props = System.getProperties(); props.put("mail.smtp.host", mailhost); Session session = Session.getInstance( props ); Message msg = new MimeMessage(session); msg.setFrom( new InternetAddress( from ) ); msg.setRecipient( RecipientType.TO, new InternetAddress( to ) ); msg.setSubject( subject ); msg.setText( content ); Transport.send( msg );

  16. Example: Email From: To: Subject: Content: Send

  17. Application Deployment Deploy Application Computer for Development Server Hosting the Web Application

  18. WAR Files Web application ARchive A JAR file for packaging, distributing, and deploying Java web applications Create WAR files The command line tool jar Eclipse Export -> Web -> WAR file

  19. Deploy WAR Files to a Tomcat Server Place the WAR file under a specific directory webapps for Tomcat autodeploy for GlassFish Manager console or web interface

More Related