Web Enabled Java Programming Lab Manual(MCAN-394B)
Web Enabled Java Programming Lab Manual(MCAN-394B)
Manual
Course Outcome:
Upon successful completion of this course, students will be able to:
• Objective: Understand the basics of Servlet technology and how to handle HTTP requests
and responses.
• Lab Exercises:
1. Set up a simple HTML form for user input and create a corresponding servlet to
process the form data.
3. Create a servlet-based application to display dynamic content using data from user
input.
Lab Solutions:
Html code:
<label for="name">Name:</label>
</form>
o Servlet (SimpleServlet.java):
Java code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
ServletException, IOException {
response.setContentType("text/html");
o Modify SimpleServlet.java to include both doGet and doPost methods, each handling
different inputs.
• Lab Exercises:
2. Implement communication from the servlet to the applet, such as sending data back
to the applet for display.
Lab Solutions:
Java code:
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
try {
connection.setDoOutput(true);
out.println("data=SampleData");
out.close();
InputStreamReader(connection.getInputStream()));
in.close();
} catch (Exception e) {
Java code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
ServletException, IOException {
response.setContentType("text/plain");
}
}
• Lab Exercises:
1. Set up a JSP page that dynamically displays content based on user input.
Lab Solutions:
Jsp code:
</form>
Jsp code:
• Lab Exercises:
1. Create a JavaBean to store user information and use it within a JSP page.
2. Develop a JSP application that utilizes JavaBeans to separate business logic from
presentation.
3. Implement an e-commerce cart system using JavaBeans and JSP for managing items
and totals.
Lab Solutions:
Java code:
Jsp code:
• Objective: Understand the basics of EJBs and their usage in enterprise-level applications.
• Lab Exercises:
2. Implement session beans (stateless and stateful) and use them in a sample
application.
3. Create a basic online banking application to manage user accounts with EJB.
Lab Solutions:
Java code:
import javax.ejb.Stateless;
@Stateless
Java code:
import javax.ejb.Remote;
@Remote
• Lab Exercises:
3. Develop an application to manage employee records with JDBC for data storage and
retrieval.
Lab Solutions:
import java.sql.*;
try {
"user", "password");
while (rs.next()) {
System.out.println(rs.getString("name"));
conn.close();
} catch (Exception e) {
e.printStackTrace();
• Lab Exercises:
2. Create an email-sending web application that takes user input (email, subject, body)
and sends emails.
Lab Solutions:
Java code:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
props.put("mail.smtp.host", "smtp.example.com");
props.put("mail.smtp.auth", "true");
});
try {
message.setFrom(new InternetAddress("from-email@example.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to-
email@example.com"));
message.setSubject("Test Email");
Transport.send(message);
System.out.println("Email Sent!");
} catch (MessagingException e) {
e.printStackTrace();
}
Unit 8: Building Web Applications
• Lab Exercises:
1. Develop a web application integrating HTML, JSP, JavaBeans, EJB, and JDBC (e.g., an
e-commerce site, job portal, or blog platform).
Lab Solutions:
o Combine HTML forms, JSP, Servlets, JavaBeans, and JDBC into a single project, such
as an E-commerce application.
o Incorporate Authentication using sessions and simple access control for restricted
pages.