0% found this document useful (0 votes)
37 views12 pages

Software Project Management

The document describes a JSP program that uses JSTL tags to add, delete, and display records from a StudentMaster database table. The program includes JSP files for displaying the student records in a table (StudentMaster.jsp), deleting a selected record (DeleteStudent.jsp), and the necessary XML configuration (web.xml). On submitting the delete button, the record is removed from the database table and the user is redirected back to the display page.

Uploaded by

s1062230079
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)
37 views12 pages

Software Project Management

The document describes a JSP program that uses JSTL tags to add, delete, and display records from a StudentMaster database table. The program includes JSP files for displaying the student records in a table (StudentMaster.jsp), deleting a selected record (DeleteStudent.jsp), and the necessary XML configuration (web.xml). On submitting the delete button, the record is removed from the database table and the user is redirected back to the display page.

Uploaded by

s1062230079
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
You are on page 1/ 12

Saurabh kumar jayprakash pandey

RollNo:79

Assignment No 1: Based on web application development using JSP

Q1. Design loan calculator using JSP which accepts Period ofTime (in years) and PrincipalLoan
amount. Display the interestpaid for the amount over the term of the loan for the followingtime
period and interest rate:

Code:
index.jsp:

<!DOCTYPE html>
<html>
<head>
<title>Loan Calculator</title>
</head>
<body>
<h1>Loan Calculator</h1>

<form action="result.jsp" method="post">


Principal Loan Amount: <input type="number" name="principal" required><br><br>
Period of Time (in years): <input type="number" name="years" required><br><br>
<input type="submit" value="Calculate">
</form>
</body> </html>
result.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-
8"%>
<!DOCTYPE html>
<html>
<head>
<title>Interest Calculation</title>
</head>
<body>
<h1>Interest Calculation Results</h1>

<%-- Retrieve form parameters --%>


<% int principal = Integer.parseInt(request.getParameter("principal")); int
years = Integer.parseInt(request.getParameter("years"));
%>

<p>Principal Loan Amount: $<%= principal %></p>


<p>Period of Time (in years): <%= years %></p>

<table border="1">
Saurabh kumar jayprakash pandey
RollNo:79

<tr>
<th>Time Period (Years)</th>
<th>Interest Rate</th>
<th>Interest Paid</th>
</tr>
<%
double interestRate; double
totalInterestPaid = 0; for (inti
= 1; i<= years; i++) {
if (i>= 1 &&i<= 7) { interestRate
= 0.0535;
} else if (i>= 8 &&i<= 15) { interestRate
= 0.055;
} else { interestRate
= 0.0575;
}

double interestPaid = principal * interestRate;


totalInterestPaid += interestPaid;
%>
<tr>
<td><%= i %></td>
<td><%= interestRate * 100 %>%</td>
<td>$<%= String.format("%.2f", interestPaid) %></td>
</tr>
<%
}
%>
</table>
<p>Total Interest Paid: $<%= String.format("%.2f", totalInterestPaid) %></p>

</body>
</html>

Output:
Saurabh kumar jayprakash pandey
RollNo:79

a. 1 to 7 year at 5.35%

Output:

b. 8 to 15 year at 5.5%
Output:
Saurabh kumar jayprakash pandey
RollNo:79

c. 16 to 30 year at 5.75%

Output:
Saurabh kumar jayprakash pandey
RollNo:79

Q2. Write a program to demonstrate Custom tag.

Code:
Saurabh kumar jayprakash pandey
RollNo:79

CustomTag.java

package demo;
import java.util.Calendar; import
javax.servlet.jsp.JspException; import
javax.servlet.jsp.JspWriter; import
javax.servlet.jsp.tagext.TagSupport; public
class CustomTag extends TagSupport{

public intdoStartTag() throws JspException {


JspWriter out=pageContext.getOut();//returns the instance of JspWriter try{
out.print(Calendar.getInstance().getTime());//printing date and time using JspWriter
}catch(Exception e){System.out.println(e);} return
SKIP_BODY;//will not evaluate the body content of the tag
}
}

Customtaglib.tld

<?xml version="1.0" encoding="ISO-8859-1" ?>


<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>

<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>simple</short-name>
<uri>http://tomcat.apache.org/example-taglib</uri>

<tag>
<name>today</name>
<tag-class>demo.CustomTag</tag-class>
</tag>
</taglib>

Index.jsp

<%@ tagliburi="WEB-INF/customtaglib.tld" prefix="m" %>


Current Date and Time is: <m:today/>

Output:
Saurabh kumar jayprakash pandey
RollNo:79

Q3. Write a program to demonstrate Session tracking, create a Student directory


student(name,email,password) and store all the information within a db. Create student login
form. Validate user form data in database (mysql) and redirect to dashboard where user
canlogout.

Code:
Database code:

Create database student;


Use student;
Create table student100
(s_name varchar (20), s_passwordvarchar(20)); select
* from student100;
insert into student100 values("Jagadish","jaggu1@");

Login.jsp:

<fieldset style="width:30%; border:3px solid black">


<legend>
Login</legend>
<form action="LoginUser.jsp" method="post">
<table>
<tr>
<td>User Name:</td>
<td><input type="text" name="name" /></td>
<tr>
<td>password:</td>
<td><input type="password" name="pass"/></td>
</tr><tr><td><input type="submit" value="Login"/></td>
</tr></table>
</form>
</fieldset>
LoginUser.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-


8859-1" %>
<%@ page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
Saurabh kumar jayprakash pandey
RollNo:79

</head>
<body>
<%
String I_name=request.getParameter("name");
String I_Password=request.getParameter("pass");
Class.forName("com.mysql.cj.jdbc.Driver"); Connection
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","root");
String query="select * from student100 where s_name=? and s_password=?";
PreparedStatementps=conn.prepareStatement(query); ps.setString(1,I_name);
ps.setString(2,I_Password); ResultSetrs=ps.executeQuery(); if (rs.next())
{ session.setAttribute("name",I_name);
response.sendRedirect("Dashboard.jsp");
} else {
response.sendRedirect("Login.jsp");
}
%>
</body> </html>

Dasboard.jsp:

<html>
<body>
<%
if(session.getAttribute("name")!=null){
%>
<h1 style="text-align:center">
Welcome to my page "<%=session.getAttribute("name")%>"
</h1>
<br>
<a style="display: block;text-align:center" href="Logout.jsp">
Click here to Logout</a>
<%
}else{
response.sendRedirect("Login.jsp"); }
%>
</body></html>

Logout.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<body>
Saurabh kumar jayprakash pandey
RollNo:79

<% session.invalidate();
%>
<p>you have been successfully logged out!</p>
</body>
</body>
</html> Output:

Saurabh

Q4. Write a jsp Program to add, delete and display the records from the
StudentMaster (Roll no. , Name , Semester, Course) Table (Using JST5L Tags)

Database :
Saurabh kumar jayprakash pandey
RollNo:79

StudentMaster.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ tagliburi="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>


<%@ tagliburi="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html>
<html>
<head>
<head> <style>
table, th, td {
border: 1px solid black;
}
</style>

<meta charset="UTF-8">
<title>Insert title here</title>
</head> <body>

<sql:setDataSourcevar="db" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/STUDENT" user="root" password="root" />

<sql:updatedataSource="${db}" var="insertRow">
UPDATE StudentMaster SET Semester="SEM 1" where RollNo=2; </sql:update>
<sql:querydataSource="${db}" var="rs">
select * from StudentMaster; </sql:query>
Saurabh kumar jayprakash pandey
RollNo:79

<form action="DeleteStudent.jsp">
<table>
<tr>
<td>ID</td>
<td>Name</td>
<td>Semester</td> <td>Course</td>
</tr>
<c:forEachvar="table" items="${rs.rows}">
<tr>
<td><c:out value="${table.rollno}"></c:out></td>
<td><c:out value="${table.name}"></c:out></td>
<td><c:out value="${table.semester}"></c:out></td>
<td><c:out value="${table.course}"></c:out></td>
<td><button type="submit" name="delete"

value="${table.rollno}">Delete</button></td>
</tr>
</c:forEach>
</table>
</form>

</body>
</html>

DeleteStudent.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>


<%@ tagliburi="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@ tagliburi="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<sql:setDataSourcevar="db" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/STUDENT" user="root" password="root" />
<sql:updatedataSource="${db}"> delete from StudentMaster where
RollNo=<%=Integer.parseInt(request.getParameter("delete"))%> </sql:update>
<c:redirecturl="StudentMaster.jsp"></c:redirect>
</body>
</html>
Saurabh kumar jayprakash pandey
RollNo:79

Web.xml

<?xml version="1.0" encoding="UTF-8"?>


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>Module_2</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>StudentMaster.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

OutPut:

You might also like