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
JSP Project

JSP Project
  • Enter Project Name--> Click Next
JSP Project

Choosing and Adding the Server to Jsp Project :

  • Choosing Server
JSP Project
  • Glass Fish Server Not Found----> Click on Add---> choose the Glass Fish Server From Menu
JSP Project

JSP Project
  • 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
JSP Project
  • 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
JSP Project
  • Open WEB-INF Folder->Check if Glass Fish Server is Visible.
JSP Project
  • Check if index.html file is visible under WEB-INF
JSP Project
  • 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
JSP Project

Output of Build Project :

JSP Project

Selecting the Default Browser for Server :

  • Click on Globe Icon---->List of Browsers Opened--->Choose Chrome Browser
JSP Project

Executing the Project :

  • Click on the Run Button
JSP Project

Creating a new JSP File :

  • Right Click on WebPages--->Select New
JSP Project
  • Under New--->Choose JSP
JSP Project
  • Under JsP file window----->Choose a File Name---->Click On Next
JSP Project

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
go

Java 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>



Related Searches to Prime Number Program in Java - Java Program to Print Prime Numbers