AJava Practical 8
AJava Practical 8
AIM: JSP
A. DISPLAY DATE
CODE:
newjsp.jsp:
<%--
Document : newjsp
Author : Lenovo
--%>
<!DOCTYPE html>
<html>
<head>
<title>Display Date</title>
</head>
<body>
<h1>Display Date</h1>
<%
%>
</body>
</html>
OUTPUT:
B. ORDER FORM
CODE:
newjsp.jsp:
<%--
Document : newjsp
Created on : Sep 13, 2024, 8:47:57 PM
Author : Lenovo
--%>
<!DOCTYPE html>
<html>
<head>
<title>JSP</title>
</head>
<body>
<center><h1>Order Form</h1></center>
<%!
%>
<tr>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
<th>Total Price</th>
</tr>
<%
%>
<tr>
</tr>
<%
%>
</table>
</body>
</html>
OUTPUT:
C. EVEN OR ODD, MULTIPLICATION
TABLE, FACTORIAL OF A NUMBER
ENTERED BY USER
CODE:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<servlet>
<servlet-name>newjsp</servlet-name>
<jsp-file>/newjsp.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>newjsp</servlet-name>
<url-pattern>/newjsp.jsp</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Number Processing</title>
</head>
<body>
<center><h1>Number</h1></center>
<br><br>
</form>
</body>
</html>
newjsp.jsp:
<%--
Document : newjsp
Author : Lenovo
--%>
<!DOCTYPE html>
<html>
<head>
<title>JSP</title>
</head>
<body>
<%
if (num % 2 == 0) {
} else {
int mul;
String table;
mul = num * i;
int fact = 1;
%>
</body>
</html>
OUTPUT:
D. FIBONACCI SERIES OF NUMBER
ENTERED BY USER
CODE:
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fibonacci Form</title>
</head>
<body>
<h1>Fibonacci Series</h1>
</form>
</body>
</html>
newjsp.jsp:
<%--
Document : newjsp
Author : Lenovo
--%>
<!DOCTYPE html>
<html>
<head>
<title>JSP</title>
</head>
<body>
<%!
int n;
String str;
int fibo(int n) {
if(n < 2)
return n;
else
%>
<%
str = request.getParameter("val");
n = Integer.parseInt(str);
out.println(fibo(i) + "<br>");
%>
</body>
</html>
OUTPUT:
E. CALCULATE POWER OF 2
CODE:
newjsp.jsp:
<%--
Document : newjsp
Author : Lenovo
--%>
<!DOCTYPE html>
<html>
<head>
<title>JSP</title>
</head>
<body>
<tr><th>Exponent</th><th>2^Exponent</th></tr>
<tr>
<td><%= i %></td>
</tr>
<% } %>
</table>
</body>
</html>
OUTPUT:
<html>
<head>
<meta charset="UTF-8">
<title>Number Processing</title>
</head>
<body>
<br><br>
</form>
</body>
</html>
newjsp.jsp:
<%--
Document : newjsp
Author : Lenovo
--%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<%
if (number <= 1) {
isPrime = false;
} else {
if (number % i == 0) {
isPrime = false;
break;
out.println("<p>" + number + " is " + (isPrime ? "a prime number." : "not a prime number.") +
"</p>");
%>
</body>
</html>
OUTPUT: