JSP Projects with Source Code
Creating a New Project :
- File--> New Project--> Under Choose Project--> Select Java with ANT-> Select Java Web-> WebApplication-> Click on Next
- Enter Project Name--> Click Next
Choosing and Adding the Server to Jsp Project :
- Choosing Server
- Glass Fish Server Not Found----> Click on Add---> choose the Glass Fish Server From Menu
- Choose your server installation location--> select the licence agreement--> click on download now button to choose your Glass fish Server Version 4.1----> Click next---> Under Domain Location--> click Next -> Glass Fish Server will be added to the menu
- After adding the server ----> choose the server -----> Choose Java EE Latest Version -----> click next---> donot choose any framework--> click on Finish Button--> Jsp Project Ready.
Verifying the Configuration :
- Expand the Project - >Choose WEB-INF file
- Open WEB-INF Folder->Check if Glass Fish Server is Visible.
- Check if index.html file is visible under WEB-INF
- Under Libaries folder---->Check if Glass Fish Server is attached.--->If visible project ready with the configurations--->Verified the Configurations.
Executing the Project :
Building the Project :
- Menu----> Run---> Build Project
Output of Build Project :
Selecting the Default Browser for Server :
- Click on Globe Icon---->List of Browsers Opened--->Choose Chrome Browser
Executing the Project :
- Click on the Run Button
Creating a new JSP File :
- Right Click on WebPages--->Select New
- Under New--->Choose JSP
- Under JsP file window----->Choose a File Name---->Click On Next
JSP Projects with Source Code :
Database Code for JSP
create table student
(
id int identity(1,1),
sname varchar(100),
sage int
)
go
select * from student
go
create procedure sp_addstudent
( @sname varchar(100),@sage int)
as begin
insert into student values(@sname,@sage)
end
goJava Libraries
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%
PreparedStatement pst1=null;
if(request.getParameter("submit")!=null)
//Step 1.1: Get the data from the text boxes
{
String name = request.getParameter("sname");
String age = request.getParameter("sage");
////Step 1 : Connection -> ServerName, Database Name, UserName, Password
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn= DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;databaseName=venkatdatabase;TrustServerCertificate=True;user=nandha;password=nandha");
//Step 2 : Prepare the SQL Command
String sql = "exec sp_addstudent ?,?"; ///exec sp_addstudent " "," "
/// prepare statement -> we are trying to prepare a sql with dynamic paramaters
///
pst1 = conn.prepareStatement(sql);
pst1.setString(1, name); ///exec sp_addstudent "venkat"," "
pst1.setString(2, age); ///exec sp_addstudent "venkat","20"
// Step 3 : Execute the SQL Command
///if it is insert or update or delete... use the command executeUpdate()
int i = pst1.executeUpdate();
// Step 4 : Get the result as postive or negative
//Step 5 : Confirm whether it is inserted.
if(i>0)
{
%>
<script>
alert("added successfully”);
</script>
<%
}
else
{
%>
<script>
alert("Not added");
</script>
<%
}
}
%>
<!DOCTYPE html>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Kaashiv Infotech JSP Page!</h1>
<div class="container">
<h2>Add Student Details</h2>
<div class="col-sm-4">
<form method="POST" action="#" >
<div class="row">
<label class="form-label">Student Name</label>
<input type="text" class="form-control" placeholder="student peyarai kodu" name="sname" id="sname" required >
</div>
<div class="row">
<label class="form-label">Student age</label>
<input type="text" class="form-control" placeholder="Student age" name="sage" id="sage" required >
</div>
<br>
<div class="row">
<input type="submit" id="submit" value="submit" name="submit" class="btn btn-warning">
</div>
</form>
</div>
</div>
</body>
</html>