Java Reference
In-Depth Information
With this annotation, we can now define and use objects of
Session
type as in the
case of the following code which is an example to show how to use
@MailSes-
sionDefinition
:
@MailSessionDefinition(
name = "java:app/env/MyMailSession",
transportProtocol = "SMTP",
user = "username@gmail.com",
password = "user_password"
//...
)
@WebServlet(name = "MailSenderServlet")
public class MailSenderServlet extends
HttpServlet {
@Resource(lookup="java:app/env/MyMailSession")
Session session;
public void doPost(HttpServletRequest
request, HttpServletResponse response)
throws IOException, ServletException {
//...
}
}
While the
@MailSessionDefinition
annotation allows us to define
MailSes-
sion
,
@MailSessionDefinitions
annotation allows us to configure many
MailSession
instances. The following code shows how to define two
MailSes-
sion
using instances
@MailSessionDefinitions
at a time:
@MailSessionDefinitions(
{ @MailSessionDefinition(name = "java:/
en/..."),
@MailSessionDefinition(name = "java:/en/
...") }
)