AJ - Question Bank With Answer
AJ - Question Bank With Answer
3. What are the key interfaces and classes in the Servlet API?
Answer:
Key Interfaces:
1. Servlet – The basic interface that every servlet must implement.
2. ServletRequest – Provides request data from the client.
3. ServletResponse – Allows the servlet to send a response to the client.
4. HttpServletRequest – Handles HTTP-specific request data.
5. HttpServletResponse – Handles HTTP-specific response data.
Key Classes:
1. GenericServlet – A general implementation of the Servlet interface.
2. HttpServlet – An abstract class used for handling HTTP requests.
4. What are the advantages of Servlets over CGI?
Answer:
Feature CGI (Common Gateway Interface) Servlets
Performance Slower (New process created for each request) Faster (Uses threads instead of processes)
Memory High (Multiple processes consume more Low (Threads share memory, reducing
Usage memory) overhead)
Scalability Poor (High load causes performance issues) High (Efficient request handling)
Security Limited Supports authentication and session tracking
UNIT – II
Important questions with answers from Unit-II of Advanced Java Programming (JSP – Java Server Pages).
7. What is JavaMail API? How can you send an email using JSP?
Answer:
JavaMail API allows sending and receiving emails in Java applications.
✅ Steps to Send an Email in JSP:
1. Add JavaMail Library (mail.jar, activation.jar).
2. Set SMTP Properties (Gmail SMTP: smtp.gmail.com).
3. Authenticate Sender Email.
4. Compose and Send Email.
✅ JSP Code to Send Email:
jsp
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
String recipient = "[email protected]";
String sender = "[email protected]";
String host = "smtp.gmail.com";
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
Transport.send(message);
out.println("Email Sent Successfully!");
%>