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

sp_adduserdata


ALTER procedure [dbo].[sp_adduserdata]
(
    @name varchar(100),
        @uname varchar(100),
        @pwd varchar(100)
)
as begin
    
                       --- database validation
     insert into tbl_user(name, uname,pwd)
        values(@name,@uname,@pwd)
end

sp_getuserdata


ALTER procedure [dbo].[sp_getuserdata]
as begin
   select * from tbl_user
end

sp_loginuser

ALTER procedure [dbo].[sp_loginuser]
( 
        @uname varchar(100),
        @pwd varchar(100)
)
as begin 
      select name from tbl_user
                  where uname = @uname and pwd=@pwd 
end

sp_searchuserdata


ALTER  procedure [dbo].[sp_searchuserdata]
(
 @searchdata varchar(100)
)
as begin
   select * from tbl_user where uname like '%'+@searchdata+'%'
end

Java Libraries

Home Page

try{
               PreparedStatement pst = null;
               if(request.getParameter("submit")!=null)
               {
               String login = request.getParameter("login"); 
               String pwd = request.getParameter("pwd"); 
               Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
               Connection con = DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;"+ "databaseName=bottle_manufacturing_March-23;"+
 "TrustServerCertificate=True;user=aaa;password=aaa");
               
               String sql = "exec sp_loginuser ?,?";   
               pst = con.prepareStatement(sql); 
               
               pst.setString(1, login);
               pst.setString(2, pwd);
               ResultSet rs=  pst.executeQuery();
                              
               if (rs.next())   ///fetch the data from the result set
               { 
                 String loggedinUser=rs.getString("name");
                  if(loggedinUser != null){
              %>
                  <script>alert("Valid user. Welcome");</script>
                 <%
                      response.sendRedirect("Dashboard.jsp?user="+loggedinUser);
                      session.setAttribute("user1",loggedinUser);
                   }
                   else{
%>
                 <script>alert("Invalid user. Problem Login");</script>
                 <%}
    }
                 else
                 {
                   %>
                   <script>alert("Invalid user. Problem Login")</script>
                   <%
                     }
                
    }
}//end of try
    catch(Exception e){
        %>
    <script>alert("Invalid User. Problem in Login")</script>
      <%
       
    }//end of catch
       %>  
   
<!DOCTYPE html>
<html>
    <head>      
     <!-- Latest compiled and minified CSS-BootStrap Link -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -BootStrap Link-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
       <meta name="viewport" content="width=device-width, initial-scale=1">  
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
    <h1>Kaashiv Infotech Login Page!</h1>     
    <div class="container">
        <h2>Login Page</h2>
        <div class="col-sm-4">
            <form  method="POST" action="#" >
                <div class="row">
                    <label class="form-label">Login Name</label> 
                    <input type="text" class="form-control" placeholder="Login Name" 
                  name="login" id="login" required >
                </div>
                <div class="row">
                    <label class="form-label">Password</label> 
                    <input type="text" class="form-control" placeholder="Password" 
                    name="pwd" id="pwd" 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>

New User Registeration Page

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%
    try    
    {
        PreparedStatement pst=null; //prepare a statement for execution
       if(request.getParameter("submit") != null) //submit button aluthi vitaya ilaya
        { 
           String name = request.getParameter("name");
           String login = request.getParameter("login"); // datavai eduthu vidu
           String pwd = request.getParameter("pwd");  //pwd text box datavai eduthu vidu
           Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
           Connection conn= DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;"
           + "databaseName=bottle_manufacturing_March-23;"
           + "TrustServerCertificate=True;user=aaa;password=aaa");
           
            //if it is insert or update or delete... use the command executeUpdate()
                       int i = pst.executeUpdate();
      //              Step 4 :  Get the result  as postive or negative
                     if (i==1)   ///fetch the data from the result set
                  {                      
                      %>
                         <script> alert("User Added Successfully!!!.Welcome");</script>
                           <%
                                response.sendRedirect("Home.jsp");   
                     }
                        else
                      {
                        %>
                          <script> alert("Problem in adding user.");</script>
                            <%
                        }                        
            }  
    }//end of try block
    catch(Exception ex)
    {
        %>
        <script> alert("Problem in adding user.")</script>
         <%
        }
      %>          
 
      <!DOCTYPE html>
<html>
    <head>
    <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>New User Page</h1>
        <div class="container">
        <h2>Login Page</h2>
        <div class="col-sm-4">
            <form  method="POST" action="#" >
                  <div class="row">
                         <label class="form-label">Name</label> 
                         <input type="text" class="form-control" placeholder="Name" name="name" id="name" required >
              </div>
                <div class="row">
                         <label class="form-label">Login Name</label> 
                         <input type="text" class="form-control" placeholder="Login Name" name="login" id="login" required >
              </div>
                <div class="row">
                      <label class="form-label">Password</label> 
                         <input type="text" class="form-control" placeholder="Password" name="pwd" id="pwd" 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>

Dashboard Page

<%@page contentType="text/html" pageEncoding="UTF-8"%>
 <%@page import="java.sql.*" %>
  
<!DOCTYPE html>
<html>
    <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" >
<!-- Latest compiled and minified JavaScript -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" ></script>
        <meta name="viewport" content="width=device-width, initial-scale=1">  
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
        <title>Dashboard Page</title>
    </head>
    
    <body>
       <div class="container">
        <h2>Dashboard Page</h2>
        <div class="col-sm-4">
          <% String name=(String)session.getAttribute("user1"); %>  
                <h2>Hello   <%=name %></h2>
                 <div class="row">
                    <a  href="SearchData.jsp">Search Data</a>
                </div>
                   <form  method="POST" action="#" >
                <div class="row">                               
         <input type="submit" id="submit" value="submit" name="submit" class="btn btn-warning">
                </div>
           
   <table class="table table-borderless table-dark">
                    <thead>
                      <tr>
                        <th scope="col">#id</th>
                        <th scope="col">Name</th>
                        <th scope="col">uname</th>
                        <th scope="col">pwd</th>
                      </tr>
                    </thead>
                    
                      <tbody>
                      <% 
                      PreparedStatement pst=null; //prepare a statement for execution
                     if(request.getParameter("submit") != null) //submit button aluthi vitaya ilaya
                   { 
                     Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
                     Connection conn= DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;"
                         + "databaseName=bottle_manufacturing_March-23;"
                         + "TrustServerCertificate=True;user=aaa;password=aaa");
                          String sql = "exec sp_getuserdata";  
                         pst = conn.prepareStatement(sql); 
                         ResultSet rs=  pst.executeQuery();
                         while (rs.next()) 
                          {   
                           %>       
                           <tr>
                          <td><%=rs.getString("id")%></td> 
                          <td><%=rs.getString("name")%></td>
                          <td><%=rs.getString("uname")%></td>
                          <td><%=rs.getString("pwd")%></td>
                           </tr>
                           <%
                               }
                            }
                          %>
                   </tbody>
                  </table>
                   </form>
        </div><!-- comment -->
       </div>
    </body>
</html>

Search Data Page

<%@page contentType="text/html" pageEncoding="UTF-8"%>
 <%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
    <head>
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" ></script>
      <meta name="viewport" content="width=device-width, initial-scale=1">  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Search Data Page</title>
    </head>
    
    <body>
       <div class="container">
        <h2>Dashboard Page</h2>
        <div class="col-sm-4">
          <% String name=(String)session.getAttribute("user1"); %>  
                <h2>Hello   <%=name %></h2>
                <div class="row">
                    <a href="SearchData.jsp">Search Data</a>
                   <form  method="POST" action="#" >
                        <div class="row">
                         <label class="form-label">Search Data</label> 
                         <input type="text" class="form-control" placeholder="Search Data" name="search" id="search" required >
              </div>
                <div class="row">                               
                         <input type="submit" id="submit" value="submit" name="submit" class="btn btn-warning">
                </div>   
                <table class="table table-borderless table-dark">
                    <thead>
                      <tr>
                        <th scope="col">#id</th>
                        <th scope="col">Name</th>
                        <th scope="col">uname</th>
                        <th scope="col">pwd</th>
                      </tr>
                    </thead>
                    <tbody>
                        
       <% 
                     PreparedStatement pst=null; //prepare a statement for execution
                    if(request.getParameter("submit") != null) //submit button aluthi vitaya ilaya
                     {                            
                        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
                        Connection conn= DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;"
                        + "databaseName=bottle_manufacturing_March-23;"
                        + "TrustServerCertificate=True;user=aaa;password=aaa");
                        String search = request.getParameter("search");  
                        String sql = "exec sp_searchuserdata ?";
                         pst = conn.prepareStatement(sql); 
                         pst.setString(1, search);
                         ResultSet rs=  pst.executeQuery();                  
                 
                          while (rs.next()) 
                                        {   
                                        %>       
                                        <tr>
                                                <td><%=rs.getString("id")%></td> 
                                                <td><%=rs.getString("name")%></td>
                                                <td><%=rs.getString("uname")%></td>
                                                <td><%=rs.getString("pwd")%></td>
                                        </tr>
                                    <%
                                        }
                            }
                                                
                        %>
                        
                   </tbody>
                  </table>
                   </form>
        </div><!-- comment -->
       </div>
    </body>
</html>

Related Searches to JSP Project With Source Code