2080 8

CSC419 ยท 2080 ยท 5 marks

What do you mean by JSP implicit objects? Discuss Java Mail API.

What do you mean by JSP implicit objects? Discuss Java Mail API. [5]

Advanced Java ProgrammingChapter 7: Servlets and Java Server pagesServlet vs JSP, JSP Access Model, JSP Syntax

Quick answer

JSP implicit objects are pre-defined objects that the JSP container automatically makes available to every JSP page without requiring the developer to explicitly declare or instantiate them. These objects can be used directly inside JSP scriptlets and expressions.

JSP Implicit Objects and Java Mail API


Part 1: JSP Implicit Objects

Note: Unlike Servlets, JSP has implicit objects while Servlet does not.

The commonly used JSP implicit objects are:

ObjectTypeDescription
requestHttpServletRequestRepresents the client HTTP request
responseHttpServletResponseRepresents the HTTP response to the client
outJspWriterUsed to write output to the response
sessionHttpSessionManages session data for a user
applicationServletContextShared data across the entire application
configServletConfigServlet configuration information
pageContextPageContextProvides access to all JSP namespaces
pageObjectRefers to the current JSP page instance (like this)
exceptionThrowableAvailable in error pages to handle exceptions

These objects simplify JSP development by removing the need for boilerplate code.


Part 2: Java Mail API

Definition

The JavaMail API is an API used to compose, write, and read electronic messages (emails). It provides a protocol-independent and platform-independent framework for sending and receiving emails.

Core Packages

  • java.mail
  • java.mail.activation

Setup Requirements

  • For J2EE 1.3 (Enterprise Edition): No additional setup required.
  • For J2SE 1.1+ (Standard Edition): Must download and install:
    • JavaMail API
    • Java Activation Framework

Sending an Email (3 Steps)

Step 1: Get the Session Object Stores all host information such as host name, username, password, etc.

Properties properties = new Properties();
Session session = Session.getDefaultInstance(properties, null);

Step 2: Compose the Message MimeMessage class is mostly used for composing the email.

MimeMessage message = new MimeMessage(session);

Step 3: Send the Message Transport class provides the method to send the message.

Transport.send(message);

Receiving an Email (Steps)

  1. Get the session object.
  2. Create the POP3 store object and connect with the POP server.
  3. Create the folder object and open it.
  4. Retrieve the messages from the folder into an array and print them.
  5. Close the store and folder objects.

Summary

FeatureDetail
PurposeSend and receive emails
NatureProtocol-independent, Platform-independent
Key ClassesSession, MimeMessage, Transport
Protocol Used (Receive)POP3
Core Packagejava.mail

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.