Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

Module 2 Assignments Java (MCA)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Module 2 Assignments Java (MCA)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Assignment No 6 : based on web application development using JSP

1. Create a Telephone directory using JSP and store all the information within a database,
so that later could be retrieved as per the requirement. Make your own assumptions. (same
as Q 3 )
2. Write a JSP page to display the Registration form (Make your own assumptions)
3. Write a JSP program to add, delete and display the records from StudentMaster
(RollNo, Name, Semester, Course) table.
4. Design loan calculator using JSP which accepts Period of Time (in years) and Principal
Loan Amount. Display the payment amount for each loan and then list the loan balance and
interest paid for each payment over the term of the loan for the following time period and
interest rate:
a. 1 to 7 year at 5.35%
b. 8 to 15 year at 5.5%
c. 16 to 30 year at 5.75%
Assignment No 6 : based on web application development using JSP

5. Write a program using JSP that displays a webpage consisting Application form
for change of Study Center which can be filled by any student who wants to
change his/ her study center. Make necessary assumptions
6. Write a JSP program to add, delete and display the records from
StudentMaster (RollNo, Name, Semester, Course) table.
7. Write a JSP program that demonstrates the use of JSP declaration, scriptlet,
directives, expression, header and footer.
How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resolved
● https://stackoverflow.com/questions/4928271/how-to-install-jstl-the-absolute-uri-http-ja
va-sun-com-jstl-core-cannot-be-r/4928309#4928309
● https://stackoverflow.com/tags/jstl/info
How to resolve HTTP 500 internal server error in Eclipse?

To solve the problem add the jar file to the WEB-INF/lib folder of the project
Design loan calculator using JSP which accepts Period of Time (in years) and
Principal Loan amount. Display the interest paid for the amount over the term of
the loan for the following time period and interest rate:
a. 1 to 7 year at 5.35%
b. 8 to 15 year at 5.5%
c. 16 to 30 year at 5.75%

Interest = (amount * rate) / 100


EMI = (amount + interest) / (year * 12)
Output
Q2 Write a program to demonstrate Session tracking, create a Student
directory student(name,email,password)and store all the information
within a db.*Note : Database program require mysql jar file present in
classpath+lib folder

Create student login form.

Validate user for data in database (mysql) and redirect to dashboard where
user can logout.
MySQL installation
Steps : https://youtu.be/2c2fUOgZMm

Installation of MySQL :
https://drive.google.com/file/d/1aU05EP5kwbo5AkAluuqt2jyFYwdjnmbh/view?
usp=sharing

Download Jar file :(Download and extract jar file from following)

https://drive.google.com/drive/folders/1azcHvOPhdwXGS57QgJlQyRlpqEzei7N
q?usp=sharing
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>
<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 import="java.sql.*"%>
<%
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/mydb","root","root");
String query="select * from student where s_name=? and s_password=?";
PreparedStatement ps=conn.prepareStatement(query);
ps.setString(1,I_name);
ps.setString(2,I_Password);
ResultSet rs=ps.executeQuery();
if (rs.next())
{
session.setAttribute("name",I_name);
response.sendRedirect("Dashboard.jsp");
}
else
{
response.sendRedirect("Login.jsp");
}
%>
Dashboard.jsp
<%
if (session.getAttribute("name") != null) {
%>
<h1 style="text-align: center">
Welcome "<%=session.getAttribute("name")%>" </h1>
<br>
<a style="display: block; text-align: right" href="Logout.jsp">
Click here to Logout</a>
<%
} else {
response.sendRedirect("Login.jsp");
}
%>
Logout.jsp

<body>

<% session.invalidate(); %>

<p>You have been successfully logout</p>

</body>

Refer more user login example :


https://www.roseindia.net/jsp/jsp-login-logout-example.shtm l
Q3 Write a program to demonstrate Custom tag (No jar file is required)
Step 1 : Create Tag Handler Class
Java class contain backend code for custom tag(user defined tag)
Create Tag handler Class
MytagHandler.java
MyTagHandler.java

public class MyTagHandler extends TagSupport{


public int doStartTag() {
try {
JspWriter out=pageContext.getOut();
out.write("Todays Date is "+ new Date());
}catch(Exception e) {
}
return SKIP_BODY;
}
}
Step 2 : Create TLD file(information about tag)

Right Click on
WEB-INF ⇒ New ⇒ File ⇒ MyLibrary.tld
MyLibrary.tld

<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<description>This is a demonstration tag library</description>
<tag>
<name>date</name>
<tag-class>com.mytagpackage.MyTagHandler</tag-class>
</tag>
</taglib>
Step 3 : Create New JSP page

<%@ taglib uri="WEB-INF/MyLib.tld" prefix="d1" %>


<body>
<h1>Hello !!!! here is my Custom tag</h1>
<d1:date></d1:date>
</body>
Q Write a JSP program to add, delete and display the records from
StudentMaster (Database)(RollNo, Name, Semester, Course) table.

Create StudentMaster table:

CREATE TABLE StudentMaster ( RollNo INT NOT NULL, Name VARCHAR (20)
NOT NULL, Semester VARCHAR (20) NOT NULL, Course VARCHAR (25),
PRIMARY KEY (RollNo) );
Create JSP pages:

● StudentMaster.jsp
● DeleteStudent.jsp

Add following jar file inside classpath and lib folder for
JSTL and Database : (JSTL library and Mysql connector
jar both are required)

https://drive.google.com/drive/folders/1azcHvOPhdwXGS57
QgJlQyRlpqEzei7Nq?usp=sharing

Official site to download all JSTL jar :

https://tomcat.apache.org/download-taglibs.cgi

Drive link :
● StudentMaster.jsp

Add following directive :


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

Style for Table :

<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
Inside body tag:

<sql:setDataSource var="db" driver="com.mysql.jdbc.Driver"


url="jdbc:mysql://localhost:3306/mydb" user="root" password="root" />
<sql:update dataSource="${db}" var="insertRow">
insert into StudentMaster values(100,'Shweta','Sem 5','MCA');
</sql:update>
<sql:update dataSource="${db}" var="insertRow">
UPDATE StudentMaster SET Semester="SEM 6", where RollNo=100;
</sql:update>
<sql:query dataSource="${db}" var="rs">
select * from StudentMaster;
</sql:query>
Form tag:
<form action="DeleteStudent.jsp">
<table>
<tr>
<td>ID</td>
<td>Name</td>
<td>Semester</td>
<td>Course</td>
</tr>
<c:forEach var="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>
● DeleteStudent.jsp

Add respective jsp directive and :

<sql:setDataSource var="db" driver="com.mysql.jdbc.Driver"


url="jdbc:mysql://localhost:3306/mydb" user="root" password="root" />

<sql:update dataSource="${db}">

delete from StudentMaster where


RollNo=<%=Integer.parseInt(request.getParameter("delete"))%>

</sql:update>

<c:redirect url="StudentMaster.jsp"></c:redirect>
Self assignment Write a JSP page to display the Registration form (Make your own
assumptions)

You might also like