Ex No: 12 JSP DEFINITION
Aim: To create a JSP page to get names and display their definition.
Algorithm
Step1: Create a folder “Ex12” to place the HTML and JSP files.
Step2: Create files “index.html” and “ex12.jsp”.
Source Code

index.html


<!DOCTYPE html>
<html>
 <head>
  <title>JSP Definition</title> 
   <meta charset="UTF-8"> 
 </head>
 <style>
  header {
   text-align:center;
   height: 100px;
   background-color: LightBlue;
   padding: 10px; 
   border-radius: 10px 10px 0px 0px;
  }
  footer {
   text-align:center;
   font-size: 12px;
   height: 50px;
   line-height: 50px;
   background-color: LightBlue;
   padding: 10px; 
   border-radius: 10px;  
  }
  section{
   width: auto; 
   border: 2px solid gray;
   padding: 10px; 
   border-radius: 10px;
   margin:5px;
  }
  input{
   border-radius: 5px;
   margin: 5px;
  }
 </style>
 <body>  
  <header>
   <h1>JSP Definition</h1>  
  </header>  
  <article>
    <section>  
     <form method="POST" action="ex12.jsp">
    <label>Enter Name:</label>
    <input type="text" name="txtname" /><br>
    <input type="submit" value="Submit"/>
     </form> 
    </section>
  </article>
  <footer>
   Developed by K. Anbarasan
  </footer>
 </body>
</html>

ex12.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" %>
<%@ page import="java.lang.String" %>
<%@ page import="java.lang.*" %>
<!DOCTYPE html>
<html>
 <head>
  <title>JSP Definition</title> 
   <meta charset="UTF-8"> 
 </head>
 <style>
  header {
   text-align:center;
   height: 100px;
   background-color: LightBlue;
   padding: 10px; 
   border-radius: 10px 10px 0px 0px;
  }
  footer {
   text-align:center;
   font-size: 12px;
   height: 50px;
   line-height: 50px;
   background-color: LightBlue;
   padding: 10px; 
   border-radius: 10px;  
  }
  section{
   width: auto; 
   border: 2px solid gray;
   padding: 10px; 
   border-radius: 10px;
   margin:5px;
  }
  input{
   border-radius: 5px;
   margin: 5px;
  }
 </style>
 <body>  
  <header>
   <h1>JSP Definition</h1>  
  </header>  
  <article>
    <section>  
     <%
       String[] names = {"HTML","JSP","XML","CSS","JS"};
       String[] def = {"HyperText Markup Language", "Java Server Page","eXtensible Markup Language", "Cascaded Style Sheet", "Java Script"}; 
       String nameval, definition;
       nameval = (String)request.getParameter("txtname");
       definition = "Definition Not Found";
       int i;  
       for(i=0;i<5;i++)
       {
        if(nameval.equals(names[i]))
        {
         definition = def[i];    
        }
       }
    %> 
    <p>Definition of <%=nameval%> is "<%=definition%>"</p>
    </section>
  </article>
  <footer>
   Developed by K. Anbarasan
  </footer>
 </body>
</html>

Result: Thus JSP page is written to get name and display definition.