Practical List

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1) Write a Java Bean program which accept the fields like (Student_ID,Student_Name) and same

fields can be fetch on next page.


Form.html Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="studentinfo.jsp" method="post">
<center>
<h1>Student Information</h1>
Roll:<input type="text" name="roll" required><br><br>
Name:<input type="text" name="sname" required><br><br>
City:<input type="text" name="city" required><br><br>
<input type="submit" value="Save">
</center>
</form>
</body>
</html>

studentinfo.jsp Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-
8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String roll1=request.getParameter("roll");
String sname1=request.getParameter("sname");
String city1=request.getParameter("city");

out.println("<h1>Roll="+roll1+"</h1>");
out.println("<h1>SName="+sname1+"</h1>");
out.println("<h1>City="+city1+"</h1>");

%>

</body>
</html>
2) Write a Java Bean program which accept two numbers in textbox and print addition of numbers
on next page.
Form.html Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="result.jsp"" method="post""">
<center>
<h1>calculator</h1>
No1<input type="text" name="no1">
No2<input type="text" name="no2">
<input type="submit" value="Submit">
</center>
</form>

</body>
</html>

Result.jsp Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String no1=request.getParameter("no1");
String no2=request.getParameter("no2");
int res=Integer.parseInt(no1)+Integer.parseInt(no2);
out.println("Addition ="+res);
%>
</body>
</html>
3) Write a JSP page, which accepts user name in a text box and greets the user according to the time
on server machine.
Form.html Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

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


Enter Your Name : <input type="text" name="name"><br>
<input type="submit" value="Submit">
</form>

</body>
</html>

Greetmsg.jsp Code:
<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%

String name = request.getParameter("name");

Calendar rightnow = Calendar.getInstance();


int time = rightnow.get(Calendar.HOUR_OF_DAY);

if(time > 0 && time <= 12)


{
out.println("Good Morning "+name);
}
else if(time < 12 && time >=16)
{
out.println("Good Afternoon "+name);
}
else
{
out.println("Good Night "+name);
}
%>

</body>
</html>
4) Write a JSP program to calculate sum of first and last digit of a given number & display sum in
Red Color with font size 18.
Form.html Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

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


Enter Any Number : <Input type=text name=num>
<input type=submit value=Display>
</form>

</body>
</html>

Displaysum.jsp Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%! int n,rem,r; %>


<% n=Integer.parseInt(request.getParameter("num"));

if(n<10)
{
out.println("Sum of first and last digit is ");
%><font size=18 color=red><%= n %>
<%

else

rem=n%10;
do
{
r=n%10;
n=n/10;
}while(n>0);
n=rem+r;
out.println("Sum of first and last digit is ");
%><font size=18 color=red><%= n %>
<%
}
%>

</body>
</html>
5) Write a java program to design a following GUI (Use JSP).

Guidelines:
For this practical, you should design the web page (i.e. html page) with basic tags in html and
whatever information is entered by user that should be displayed on your jsp page.

You might also like