0% found this document useful (0 votes)
2 views13 pages

Web Development With Java Practicals Solution

Uploaded by

realcarefan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views13 pages

Web Development With Java Practicals Solution

Uploaded by

realcarefan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Web Development with JAVA – Practical Solutions

16. Installation of Apache Tomcat Server

Steps:

1. Download Apache Tomcat from the official website.


2. Install Java JDK first.
3. Extract Tomcat zip file.
4. Open the bin folder.
5. Run [Link] .
6. Open browser and type:

[Link]

Result:

Apache Tomcat server starts successfully.

17. Installation of IDE (NetBeans)


Steps:

1. Download NetBeans IDE.


2. Install Java JDK.
3. Run NetBeans installer.
4. Select installation path.
5. Complete installation.
6. Open NetBeans IDE.

Result:

NetBeans IDE installed successfully.

1
18. Deploy Simple Website in Apache Tomcat
Server
[Link]

<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<h1>Welcome to Apache Tomcat</h1>
</body>
</html>

Steps:

1. Create folder inside webapps .


2. Save [Link] in folder.
3. Start Tomcat server.
4. Open browser:

[Link]

Result:

Website deployed successfully.

19. Design a Page Layout using HTML and CSS

<!DOCTYPE html>
<html>
<head>
<style>
body{
font-family:Arial;
}
header{
background:#333;
color:white;

2
padding:20px;
text-align:center;
}
nav{
background:#555;
padding:10px;
}
nav a{
color:white;
margin:10px;
text-decoration:none;
}
section{
padding:20px;
}
footer{
background:#333;
color:white;
text-align:center;
padding:10px;
}
</style>
</head>
<body>
<header>
<h1>My Website</h1>
</header>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</nav>
<section>
<h2>Welcome</h2>
<p>This is page layout design.</p>
</section>
<footer>
Copyright 2026
</footer>
</body>
</html>

Result:

A simple webpage layout is created.

3
20. Install ODBC Driver
Steps:

1. Open Control Panel.


2. Open Administrative Tools.
3. Select ODBC Data Sources.
4. Add MySQL ODBC Driver.
5. Configure database connection.

Result:

ODBC driver installed successfully.

21. Install and Configure MySQL


Steps:

1. Download MySQL Installer.


2. Install MySQL Server.
3. Set username and password.
4. Open MySQL Command Line.
5. Create database.

SQL Query

CREATE DATABASE studentdb;

Result:

MySQL configured successfully.

22. Design User Registration Form and Store User


in Database
[Link]

<!DOCTYPE html>
<html>

4
<body>
<form action="RegisterServlet" method="post">
Name: <input type="text" name="name"><br><br>
Email: <input type="email" name="email"><br><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" value="Register">
</form>
</body>
</html>

[Link]

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

public class RegisterServlet extends HttpServlet {


protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

String name=[Link]("name");
String email=[Link]("email");
String password=[Link]("password");

try{
[Link]("[Link]");
Connection con=[Link](
"jdbc:mysql://localhost:3306/studentdb","root","root");

PreparedStatement ps=[Link](
"insert into users values(?,?,?)");

[Link](1,name);
[Link](2,email);
[Link](3,password);

[Link]();
[Link]().println("Registration Successful");

}catch(Exception e){
[Link](e);
}
}
}

5
SQL Table

CREATE TABLE users(


name VARCHAR(50),
email VARCHAR(50),
password VARCHAR(50)
);

Result:

User registration data stored in database.

23. Design Login User Form and Validate User


[Link]

<form action="LoginServlet" method="post">


Email: <input type="email" name="email"><br><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" value="Login">
</form>

[Link]

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

public class LoginServlet extends HttpServlet {


protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

String email=[Link]("email");
String password=[Link]("password");

try{
[Link]("[Link]");
Connection con=[Link](
"jdbc:mysql://localhost:3306/studentdb","root","root");

6
PreparedStatement ps=[Link](
"select * from users where email=? and password=?");

[Link](1,email);
[Link](2,password);

ResultSet rs=[Link]();

if([Link]()){
[Link]().println("Login Successful");
}else{
[Link]().println("Invalid User");
}

}catch(Exception e){
[Link](e);
}
}
}

Result:

User login validated successfully.

24. Show All Registered Users in a Grid


[Link]

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

public class ShowUsersServlet extends HttpServlet {


protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

[Link]("text/html");

try{
[Link]("[Link]");
Connection con=[Link](
"jdbc:mysql://localhost:3306/studentdb","root","root");

7
Statement st=[Link]();
ResultSet rs=[Link]("select * from users");

PrintWriter out=[Link]();

[Link]("<table border='1'>");
[Link]("<tr><th>Name</th><th>Email</th></tr>");

while([Link]()){
[Link]("<tr><td>"+[Link](1)+"</td><td>"+
[Link](2)+"</td></tr>");
}

[Link]("</table>");

}catch(Exception e){
[Link](e);
}
}
}

Result:

All users displayed in grid format.

25. Search Users by Name and Show in Grid


[Link]

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

public class SearchServlet extends HttpServlet {


protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

String name=[Link]("name");

try{
[Link]("[Link]");
Connection con=[Link](
"jdbc:mysql://localhost:3306/studentdb","root","root");

8
PreparedStatement ps=[Link](
"select * from users where name=?");

[Link](1,name);

ResultSet rs=[Link]();

PrintWriter out=[Link]();
[Link]("<table border='1'>");

while([Link]()){
[Link]("<tr><td>"+[Link](1)+"</td><td>"+
[Link](2)+"</td></tr>");
}

[Link]("</table>");

}catch(Exception e){
[Link](e);
}
}
}

Result:

User searched successfully.

26. Update User Profile


[Link]

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

public class UpdateServlet extends HttpServlet {


protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

String email=[Link]("email");
String name=[Link]("name");

9
try{
[Link]("[Link]");
Connection con=[Link](
"jdbc:mysql://localhost:3306/studentdb","root","root");

PreparedStatement ps=[Link](
"update users set name=? where email=?");

[Link](1,name);
[Link](2,email);

[Link]();

[Link]().println("Profile Updated");

}catch(Exception e){
[Link](e);
}
}
}

Result:

User profile updated successfully.

27. Form Validation using jQuery

<!DOCTYPE html>
<html>
<head>
<script src="[Link]
<script>
$(document).ready(function(){
$("form").submit(function(){
var name=$("#name").val();

if(name==""){
alert("Name is required");
return false;
}
});
});
</script>
</head>

10
<body>
<form>
<input type="text" id="name">
<input type="submit">
</form>
</body>
</html>

Result:

Form validated using jQuery.

28. Create a Form using Java Servlet


[Link]

import [Link].*;
import [Link].*;
import [Link].*;

public class FormServlet extends HttpServlet {


protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

PrintWriter out=[Link]();

[Link]("<html><body>");
[Link]("<form>");
[Link]("Name:<input type='text'><br><br>");
[Link]("<input type='submit'>");
[Link]("</form>");
[Link]("</body></html>");
}
}

Result:

Form created successfully using servlet.

11
29. Store and Retrieve Data from Session
[Link]

import [Link].*;
import [Link].*;
import [Link].*;

public class SessionServlet extends HttpServlet {


protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

HttpSession session=[Link]();
[Link]("username","Admin");

String user=(String)[Link]("username");

[Link]().println("Session User: "+user);


}
}

Result:

Session data stored and retrieved successfully.

30. Create Address Book Application


[Link]

<!DOCTYPE html>
<html>
<body>
<h2>Address Book</h2>
<form>
Name: <input type="text"><br><br>
Phone: <input type="text"><br><br>
Address: <input type="text"><br><br>
<input type="submit" value="Save">
</form>
</body>
</html>

12
SQL Table

CREATE TABLE addressbook(


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
phone VARCHAR(20),
address VARCHAR(100)
);

Result:

Address Book application created successfully.

Conclusion
All Web Development with JAVA practicals completed successfully using:

• HTML
• CSS
• Java Servlet
• MySQL
• Apache Tomcat
• NetBeans
• jQuery

13

You might also like