Adv. Java Practical

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

ADVANCED JAVA

PRACTICAL
Q1. Write a program to print the IP address.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<br>Hello World!<br/>

<% out.println("Your IP Address "+ request.getRemoteAddr());

%>

</body>

</html>

OUTPUT SCREEN
Q2. Write a program using JSP declaration scriplet.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>Hello World</title>

</head>

<body>

Hello World!<br/>

<%! int i=2; %>

<% for(int j=i;j<=5;j++)

out.println(i);

%>

</body>

</html>

OUTPUT SCREEN
Q3. Write a program using JSP expression scriplets.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>A comment Test</title>

</head>

<body>

<p>

Today's Date: Today's date: <%= (new java.util.Date()).toLocaleString()%>

</p>

</body>

</html>

OUTPUT SCREEN
Q4. Write a program using JSP comments scriplet.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>A comment Test</title>

</head>

<body>

<h2> A test of comments </h2>

<!-- This comment will not be visible in the page source-->

</body>

</html>

OUTPUT SCREEN
Q5. Create a form in HTML which will take student along with 5 subject marks.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q1</title>

</head>

<body>

<form action="#" method="get">

<input type="text" placeholder="Name"><br>

<input type="text" placeholder="Roll Number"><br>

<input type="text" placeholder="Enrollment"><br>

<input type="text" placeholder="Subject 1"><br>

<input type="text" placeholder="Subject 2"><br>

<input type="text" placeholder="Subject 3"><br>

<input type="text" placeholder="Subject 4"><br>

<input type="text" placeholder="Subject 5"><br>

<input type="submit" value="Submit">

</form>

</body>

</html>
Q6. Create a Registration form.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q2</title>

</head>

<body>

<form action="#" method="get">

<input type="text" placeholder="Name"><br>

<input type="text" placeholder="Father's Name"><br>

<input type="text" placeholder="Mother's Name"><br>

<input type="date" placeholder="DOB"><br>

<input type="text" placeholder="Course"><br>

<input type="text" placeholder="10th marks"><br>

<input type="text" placeholder="12th marks"><br>

<input type="submit" value="Submit">

</form>

</body>

</html>
Q7. Create JSP page print table of a number in given format.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q4 and Q5</title>

</head>

<body>

<%! int number = 2; %>

<table border=1 cellpadding=10>

<% for(int i = 1; i<=10; i++) { %>

<tr>

<td> <%= number%> </td>

<td> * </td>

<td> <%= i%> </td>

<td> = </td>

<td> <%= number*i%> </td>

</tr>

<% } %>

</table>

</body>

</html>
Q8. Create HTML form asking student detail enrollment, name, DOB, Program, Fee
along with submit. Clicking on submit welcome.jsp shows greeting.

Index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q6</title>

</head>

<body>

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

<input type="text" name="name" placeholder="Name"><br>

<input type="text" name="enrollment" placeholder="Enrollment"><br>

<label for="dob">DOB</label>

<input type="date" name="dob" placeholder="DOB"><br>

<input type="text" name="course" placeholder="Course"><br>

<input type="text" name="fee" placeholder="Fee Applicable"><br>

<input type="submit" value="Submit">

</form>

</body>

</html>
Welcome.jsp

%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q6-Welcome</title>

</head>

<body>

<h1>Hello <%= request.getParameter("name")%></h1>

<h3>You are selected to <%= request.getParameter("course")%> <br>

Your enrollment is <%= request.getParameter("enrollment")%></h3>

</body>

</html>

H
E
L
L
O
D
I
V
Y
A
Q9. Create index.jsp where you enter a number and submit it to table.jsp where you
want to display table of given number in required format.

Index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q7</title>

</head>

<body>

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

<input type="text" name="number" placeholder="Enter a number"><br>

<input type="submit" value="Submit">

</form>

</body>

</html>
Table.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q7-Table</title>

</head>

<body>

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

<table border=1 cellpadding=10>

<% for(int i = 1; i<=10; i++) { %>

<tr>

<td> <%= number%> </td>

<td> * </td>

<td> <%= i%> </td>

<td> = </td>

<td> <%= number*i%> </td>

</tr>

<% } %>

</table>

</body>

</html>
Q10. Create index.jsp where you enter a number and submit it to math_cal.jsp where
you want to display table containing following properties odd even prime palindrome.

Index.jsp

%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q8</title>

</head>

<body>

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

<input type="text" name="number" placeholder="Enter a number"><br>

<input type="submit" value="Submit">

</form>

</body>

</html>
Math_cal.jsp
Q11. Create index.jsp and design student form having fields Name Address DOB create
check boxes for course selected print atleast 5 courses clicking on submit calls
summary.jsp which display the courses opt by student and show number of courses opt.

Index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q9</title>

</head>

<body>

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

<input type="text" name="name" placeholder="Name"><br>

<input type="text" name="address" placeholder="Address"><br>

<label for="dob">DOB</label>

<input type="date" name="dob" placeholder="DOB"><br>

<input type="checkbox" name="course" value="hindi"> Hindi<br>

<input type="checkbox" name="course" value="english"> English<br>

<input type="checkbox" name="course" value="arts"> Arts<br>

<input type="checkbox" name="course" value="biotech"> Biotech<br>

<input type="checkbox" name="course" value="computer"> Computer<br>

<input type="submit" value="Submit">

</form>

</body>

</html>
Summary.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Q9-Summary</title>

</head>

<body>

<h1>Hello, <%= request.getParameter("name")%></h1><br/>

<h3>You have selected <%= request.getParameterValues("course") == null

? 0 : request.getParameterValues("course").length%> courses</h3><br>

<h3>You have selected</h3><br/>

<table border=1 cellpadding=10>

<% for (int i = 0; i < request.getParameterValues("course").length; i++) {%>

<tr>

<td> <%= request.getParameterValues("course")[i]%> </td>

</tr>

<% }%>

</table>

</body>

</html>
Q12. Write a program to produce the following output.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Question 1</title>

</head>

<body>

<h1>table creation</h1>

<table border="1">

<tr>

<td>

<h3>LOGO</h3>

</td>

</tr>

<tr>

<td colspan="1">

<h4> MENU</h4>

</td>

<td>

<h4> CONTENT </h4>

</td>

</tr>

</table>

</body>

</html>
Q13. Write a program to produce the following output.

<html>

<head> <title>web page</title></head>

<body>

<table border="1" style="width:100%; height:100%;">

<tr>

<td>

<h2> LOGO </h2>

</td>

</tr>

<tr>

<td colspan="1">

<h4> HOME </h4> <br>

<h4>CONTACT US</h4> <br>

<h4>ABOUT US</h4>

</td>

<td>

<h3> Text </h3>

</td>

</tr>

</table>

</body>

</html>
Q14. Write a program using For loop.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<%! int fontsize; %>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<%

for ( fontsize = 20; fontsize <= 22; fontsize++)

{ %>

<font color="red" size="<%= fontsize %>"> font is getting larger </font><br/>

<%}%>

</body>

</html>
Q15. Write a if else loop program to display date.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<%! int day = 3; %>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<%

if (day == 1 | day == 7)

{ %>

<p> Today is weekend</p>

<% }

else

{ %>

<p> Today is not weekend</p>

<% } %>

</body>

</html>

You might also like