A JSP page allows you to maintain state using cookies or session object. Session object is more used for maintaining state because it is reliable than cookies. A JSP page can forward requests to other JSP pages and Sites. It allows us to use Beans in a JSP Page.
A Simple JSP Page looks like the following:
<% @ page language=”java “%>
Arithmetic Operations
<% String s, oper; int s1, s2;
s=request.getParameter(“fno”);
s1=Integer.parseInt(s);
s=request.getParameter (“sno”);
s2=Integer.parseInt (s);
oper=request.getParameter (“submit”); %>
< % if (oper.equals (“add”) { % >
Result is :< % =s1+s2 %> <% } %>
< % if (oper.equals (“sub”) { % >
Result is :< % =s1-s2 %> <% } %>
< % if (oper.equals (“mul”) { % >
Result is :< % =s1*s2 %> <% } %>
< % if (oper.equals (“div”) { % >
Result is :< % =s1/s2 %> <% } %>
Save this Jsp page as oper.jsp.The html code for the above JSP page is as follows:
 
First First no:
Second no:
That's it!
The objects mentioned in the Architecture of the Java Server Pages section are shown in the example in bold:
- The request object represents the user’s request.