Calculation 2 in Java (Using JSP) - NESTED CODE || TECH FLOAT

Breaking

Post Top Ad

Post Top Ad

Thursday, 1 November 2012

Calculation 2 in Java (Using JSP)

  Fifth Lesson on JSP


In the previous lesson we selected the no "17" statically. Now we will choose the number dynamically. 
The input interface (the page to the user in front end) will be like::

 Code for this page ::

<%--
    Document   : index
    Created on : Nov 1st, 2012, 9:11:23 PM
    Author     : Nested Code
--%>

<head><title>First Calculation</title></head>
<body>
<center><h1>Calculation in Java</h1>
We'll do some sums ...<br>
    <form action="caljsp.jsp">
            Enter the Digit :: <input type="text" value=0 name=n>
                <br>
                    <input type="submit" value="submit">
                        <br><hr>
    </form> <blink><a href="http://nestedcode.blogspot.in" >Visit Our Site</a></blink><br>
</center>
</body>


Now we again have to make the page for "caljsp.jsp". The code is ::

<%--
    Document   : caljsp
    Created on : 31 Oct, 2012, 4:45:20 PM
    Author     :NESTED CODE
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body><center>
        <% 
   
String ns= request.getParameter("n");
       
           int number=Integer.parseInt(ns);
         
         %><br>
Here is a 10 times table for <%= number %>... <br>
<table border=1>
<% for (int k=1; k<=10; k++) {
        int result = k * number; %>
<tr><td><%= k %></td><td><%= result %></td></tr>
<% }  %>
</table><hr>
<br><br>
Page written by Nested Code<br>

 <blink><a href="http://nestedcode.blogspot.in" >Visit Our Site</a></blink><br></center>

    </body>
</html>


Output will be like ::


Previous Lesson                                                                                                         Next Lesson

2 comments:

  1. Thanks for your comment... Please subscribe our blog - click the below link
    https://www.blogger.com/follow.g?view=FOLLOW&blogID=4704532048503018855Reply

    ReplyDelete
  2. Thanks for this, also if you want to learn Java programming language then find the best courses on Udemy regarding Java programming language.

    ReplyDelete

Post Bottom Ad