0% found this document useful (0 votes)
11 views

Practical List

The document provides code examples for 5 Java Bean programs that accept user input in HTML forms and display output in JSP pages. The programs include: 1) A form to accept student details and display them on another page. 2) A form to accept two numbers, calculate their addition, and display the result. 3) A form to accept a user's name and greet them with a message tailored to the current time. 4) A form to accept a number, calculate the sum of its first and last digits, and display the sum in red text at a large font size. 5) An instruction to design a GUI using JSP that displays user-entered information.

Uploaded by

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

Practical List

The document provides code examples for 5 Java Bean programs that accept user input in HTML forms and display output in JSP pages. The programs include: 1) A form to accept student details and display them on another page. 2) A form to accept two numbers, calculate their addition, and display the result. 3) A form to accept a user's name and greet them with a message tailored to the current time. 4) A form to accept a number, calculate the sum of its first and last digits, and display the sum in red text at a large font size. 5) An instruction to design a GUI using JSP that displays user-entered information.

Uploaded by

Mohit Palve
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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