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

03 JSP Examples

This document contains code snippets and examples related to Java Server Pages (JSP). It includes examples of: 1) A basic "Hello World" JSP page that displays the request method and current date. 2) An JSP page that uses a scriptlet to display an array of programming languages in a table with alternating row colors. 3) A HTML page with a form that takes two numbers as input and uses JavaScript to validate the inputs before submitting to a JSP page. 4) The JSP page that multiplies the two numbers and displays the results in a table. It uses scriptlets to parse the input and perform the calculation.

Uploaded by

nehaagrawal2210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

03 JSP Examples

This document contains code snippets and examples related to Java Server Pages (JSP). It includes examples of: 1) A basic "Hello World" JSP page that displays the request method and current date. 2) An JSP page that uses a scriptlet to display an array of programming languages in a table with alternating row colors. 3) A HTML page with a form that takes two numbers as input and uses JavaScript to validate the inputs before submitting to a JSP page. 4) The JSP page that multiplies the two numbers and displays the results in a table. It uses scriptlets to parse the input and perform the calculation.

Uploaded by

nehaagrawal2210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Deccansoft Software Services Adv Java / JSP-Examples

-------------------------first.jsp------------------------------- ---------------------multiply.html----------------------
<%@page contentType="text/html" %> <html>
<html> <head>
<body> <script language="javascript">
<h1>
function validateMyForm()
Welcome to JSP World
<br><br> {
REQUEST_METHOD: var v1 = document.myForm.num1.value;
<%= request.getMethod() %> var v2 = document.myForm.num2.value;
<br><br> var n = v1.length;
<%= new java.uti.Date().toString() %> if(n < 1)
</h1> {
</body> alert("Number 1 is Empty");
</html> return false;
----------------------ArrayDemo.jsp------------------------ }
<% else if( isNaN(v1) )
String str[] = {"C","C++","Java"};
{
%>
<html>
alert("Number 1 is NOT A NUMBER");
<body> return false;
<h1> }
<table align="center" border="1"> if(v2.length < 1)
<% {
for(int i=0; i<str.length; i++) alert("Number 2 is Empty");
{ return false;
%> }
<tr bgcolor=<%= i%2==0?"pink":"yellow" %>> else if( isNaN(v2) )
<td><%= i + 1 %></td> {
<td><%= str[i] %></td>
alert("Number 2 is NOT A NUMBER");
</tr>
<% return false;
} }
%> else return true;
</table> }
</h1> </script>
</body> </head>
</html> <body>
-------------------------a.html--------------------------------- <h1>
<h1> <form action='multiply.jsp' method='post'
This is a.html name='myForm'
</h1>
onsubmit="return validateMyForm()">
---------------------------b.html-------------------------------
<h1>
Num 1 : <input type='text' name='num1'>
This is b.html <font color='red'>*</font>
</h1> <br>
----------------------includeDemo.jsp----------------------- Num 2 : <input type='text' name='num1'>
<html> <font color='red'>*</font>
<body> <br><br>
<table border="1" width = "100%" height="100%"> <input type='submit' value='Multiply'>
<tr valign="top"> </form>
<td> <%@include file="a.html"%></td> </h1>
<td> <%@include file="b.html"%></td> </body>
</tr>
</html>
</table>
</body>
</html>

1
Deccansoft Software Services Adv Java / JSP-Examples
---------------------multiply.jsp------------------------ }
<% else
String num1 = request.getParameter("num1"); {
String num2 = request.getParameter("num2"); message = "You are not from this planet" ;
}
int a = Integer.parseInt(num1);
%>
int b = Integer.parseInt(num2); <html>
%> <body>
<html> <h1>
<body> <%= message %>
<h1> </h1>
<table align='center' border='1'> </body>
<% </html>
for(int i=1;i<=b;i++) -----------------------message.html---------------------
{ <html>
%> <body>
<tr> <h1>
<td> <%= a + " * " + i %> <form action='message' method='post'>
<td> <%= a*i %> Enter your message here: <br>
<% <textarea name='msg' rows='8' cols='50'>
} </textarea>
%> <br>
</table> Style : <input type='checkbox' name='bold'
</h1> value='bold'> Bold
</body> <br>
</html> Color:
----------------------sports.html------------------------------ <input type=’checkbox’ name=’color’
<html> value=’red’>red
<body> <input type=’ checkbox’ name=’color’
<h1> value=’green’>green
<form action='sports.jsp' method='post'> <input type=’ checkbox’ name=’color’
Select your favorite sports: <br>
value=’blue’>blue
<input type='radio' name='sport'
value='Football'> Football
<br>
<br> <input type='submit' name='submit'
<input type='radio' name='sport' value='Send'>
value='Hockey'> Hockey </form>
<br> </h1>
<input type='radio' name='sport' </body>
value='Tennis'> Tennis </html>
<br> -----------------------message.jsp-----------------------
<input type='submit' value='Submit'> <%
</form> String msgValue = request.getParameter("msg");
</h1>
String boldValue = request.getParameter("bold");
</body>
</html>
if (boldValue != null)
--------------------------sports.jsp---------------------------- msgValue = "<b>" + msgValue + "</b>" ;
<%
String message; TRY TO EMBED MESSAGE IN SELECTED
String sportsValue [] = RADIO BUTTON COLOR
request.getParameterValues ("sports"); %>
if ( sportsValue != null ) <html>
{ <body>
message = "You selected : <br>"; <%= msgValue %>
for ( int i=0; i<sportsValue.length; i++) </body>
{
</html>
message = message + sportsValue[i] + "<br>";
}
_________________________________________

You might also like