Download presentation
Presentation is loading. Please wait.
Published byVernon Rodgers Modified over 8 years ago
1
CS520 Web Programming Bits and Pieces of Web Programming (II) Chengyu Sun California State University, Los Angeles
2
Roadmap Sending email Task scheduling and execution View Template Framework Application deployment
3
Email Function in Web Applications Various notifications, e.g. order, payment, shipment, forum post and reply, account activities, and so on Advertisement campaigns and product promotions Password reset …
4
How Email Works SMTP, IMAP, POP Client AClient B Email Server AEmail Server B ??
5
JavaMail http://www.oracle.com/technetwork/java/jav amail/index.html Maven dependency: javax.mail:mail Properties props = System.getProperties(); props.put("mail.smtp.host", mailhost); Session session = Session.getInstance( props ); Message msg = new MimeMessage(session);... Transport.send( msg );
6
Set Up a Local Email Server for Testing hMailServer on Windows - http://csns.calstatela.edu/wiki/content/ cysun/course_materials/hmailserver http://csns.calstatela.edu/wiki/content/ cysun/course_materials/hmailserver postfix on Linux - http://csns.calstatela.edu/wiki/content/ cysun/notes/ubuntu_server#email http://csns.calstatela.edu/wiki/content/ cysun/notes/ubuntu_server#email
7
Spring Email Support Need spring-context-support dependency Declare a mailSender bean JavaMailSender interface JavaMailSender See CSNS2 for example Mail message classes SimpleMailMessage No attachment, no special character encoding MimeMailMessage
8
Examples of Scheduled Tasks Periodic emails, e.g. Information about weekly sale Forum daily digests Member newsletters Payment reminders Batch data processing
9
Concepts in Task Scheduling and Execution … Task Executor Use one thread for each task Use one thread for all tasks Use a thread pool Schedule (a.k.a. Trigger) E.g. every 5 minutes, every day at midnight, every first Sunday of each month at 8am …
10
… Concepts in Task Scheduling and Execution Scheduler Executor Task Schedule/Trigger
11
Spring Configuration namespace <task:executor id="executor" pool-size="5"/> <task:annotation-driven scheduler="scheduler" executor="executor" /> Creates a scheduler Creates a thread pool Based executor Enables annotations @Scheduled and @Async
12
@Scheduled http://docs.spring.io/spring/docs/curren t/javadoc- api/org/springframework/scheduling/an notation/Scheduled.html
13
Cron Expression Six field separated by space 1. Seconds (0-59) 2. Minutes (0-59) 3. Hours (0-23) 4. Day of month (1-31) 5. Month (1-12 or JAN-DEC) 6. Day of week (1-7 or MON-SUN)
14
Cron Field Values Single value, e.g. 12 Set of values, e.g. 0,15,30,45 Range, e.g. 1-12,MON-FRI,* (first- last) Range with step, e.g. 1-12/3
15
Cron Expression Examples 0 0 * * * * 0 */10 * * * * 0 0 8 * * MON-FRI 0 0 1 1,15 * * Every hour at the beginning of the hour Every 10 minutes Every weekday at 8AM Every 1 st and 15 th of each month at 1AM
16
Apache Tiles http://tiles.apache.org/ A template framework for JSP Similar to Master Page and Razor in ASP.NET
17
The Need for View Templates Header Footer Content 1 Header Footer Content N page1.jsppageN.jsp
18
Why JSP Is Not Enough It breaks HTML syntax, e.g. in header.jsp and in footer.jsp. It’s difficult to create and manage multiple complex templates.
19
Basic Tiles Usage Template page = JSP + placeholders (i.e. attributes), Content: JSP, string, other tiles Definition: combine template and content Tiles Tag Library http://tiles.apache.org/framework/tiles-jsp/tlddoc/index.html
20
A Tiles Example Header Footer Content 1 Header Footer Content 2 page1.jsppage2.jsp
21
Tiles – Template Page Header Footer template.jsp
22
Tiles – Content Pages Content 1Content 2 page1.jsppage2.jsp
23
Tiles – Definitions
24
Resolve Tiles Views in Spring /WEB-INF/tiles.xml
25
Tiles Usage in CSNS2 WEB-INF/layout for template and header/footer pages WEB-INF/content for content pages WEB-INF/tiles.xml for definitions
26
Application Deployment Computer for Development Server Hosting the Web Application Deploy Application
27
Directory Structure of a Java Web Application Application Root Directory WEB-INF JSPs and static resources classes web.xml lib Compiled Java classes Additional Java libraries
28
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 mvn package
29
Deploy WAR Files to a Tomcat Server Copy the WAR file to the webapps folder Use the Manager App Need a user with the manager-gui role More options at http://tomcat.apache.org/tomcat-7.0- doc/deployer-howto.html http://tomcat.apache.org/tomcat-7.0- doc/deployer-howto.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.