Sunday, January 16, 2011

Simple Programs in JSP


JSP is dynamic programming language. It is capable of making simple program to complex. We can make simple program of add, even numbers, odd numbers. It is good start for beginner to learn with these programs.
 Step 1 :  Create a new Project in NetBeans or Ecllips Editor as
               Ex-    File  > New > Dynamic Web Project   (In Ecllips Hellios) 

Step 2 : Configure your Tomcat Server or the Server that you use with the project that you are creating 
             by  following create project dialog box.

Step 3:  Just paste the one of the program

First program of adding two numbers in JSP

<%@ page language="java"%>
<html>
<head>
<title>Add number program in JSP</title>
</head>

<body>
<%
 int a=5;
 int b=2;
 
 int result=a+b;
  
 out.print("Additon of a and b :"+result); 
%>
</body>
</html>

Second program of subtraction two numbers in JSP

<%@ page language="java"%>
<html>
<head>
<title>Subtraction numbers program in JSP</title>
</head>
<body>
<%
 int a=5;
 int b=2;
 int result=a-b;
 out.print("Subtraction of a and b :"+result); 
%>
</body>
</html>

Third program of print even numbers in JSP
 
<%@ page language="java"%>
<html>
<head>
<title>Even number program in JSP</title>
</head>

<body>
<%
 for(int i=0;i<=10;i++) 
 {
  if((i%2)==0)
  {
   out.print("Even number  :"+i); 
   out.print("<br>");
  }
 }
%>
</body>
</html>

Forth program of print odd numbers in JSP
 
<%@ page language="java"%>
<html>
<head>
<title>Odd number program in JSP</title>
</head>

<body>
<%
 for(int i=0;i<=10;i++) 
 {
  if((i%2)!=0)
  {
   out.print("Odd number  :"+i); 
   out.print("<br>");
  }
 }
%>
</body>
</html>