Showing posts with label JSP. Show all posts
Showing posts with label JSP. Show all posts

HTML Form data and JSP


// HTML form to submit user name

<!-- html forms -->

<html>
<head>
     <title>JSP and HTML Form data</title>
     <style>
          label
          {
              font-family:vivaldi;
              font-size:x-large;
              letter-spacing:2px;
              line-height:40px;
              font-weight:bold;
          }
     </style>
</head>

<body>
     <form method="GET" action="JSPFormData.jsp">
          <center>
          <h2>JSP and HTML Form Data</h2></br>
         
          <label>Enter Name  </label>
          <input type="text" Name="UN" tabindex=1/>
          </br> </br>
         
          <button type="Submit" >Click me!!! </button>
          </center>
             
     </form>
</body>

</html>

// JSPFormData.jsp
<!-- JSP -->

<html>
<body>
<h2><center>
<% out.println("Welcome "+ request.getParameter("UN")); %>
</center></h2>
</body>
</html>

JSP Expression Language


<!-- JSP EL -->

<%@ page import = "java.io.*,java.util.*" %>

<html>
   <head>
      <title>Application object in JSP</title>
   </head>
  
   <body>
   <center><h2>
      <%
         Integer count = (Integer)application.getAttribute("hitCounter");
         if( count ==null || count == 0 )
           {
            out.println("Welcome to my website!");
            count = 1;
         }
           else
           { 
            out.println("Welcome back to my website!");
            count += 1;
         }
         application.setAttribute("hitCounter", count);
      %>
      <br/><br/>
         <p>Total number of visits: <%= count%></p>
      </h2></center>
  
   </body>
</html>

JSP include directive


// JSPMP.jsp

<!-- JSP -->

<jsp:directive.include file="JSPHdr.jsp"/>
<jsp:directive.include file="JSPCon.jsp"/>
<jsp:directive.include file="JSPFtr.jsp"/>

// JSPHdr.jsp
<!-- JSP -->

<html>  
     <body>
     <center><h2>
          Header file - Welcome to JSP
     </h2></center>
     </body>
</html>

// JSPCon.jsp
<!-- JSP -->

<html>  
     <body>
     <center><h2>
          Content - This page is about JSP
     </h2></center>
     </body>
</html>

// JSPFtr.jsp
<!-- JSP -->

<html>  
     <body>
     <center><h2>
          Footer - Created by Anurekha
     </h2></center>
     </body>
</html>

JSP Page directive and include directive


<!-- JSP Page and include directive and Attributes -->

<html>
<body>

<h2><center>
<%@ page import="java.util.*" %>
<% out.println((new Date()).toLocaleString()); %>
<br/>

<%@ page session="true" %>
<% out.println(session.getCreationTime()); %>
<br/>

<% out.println(request.getRequestURL()); %>
<br/>

<% out.println(session.getLastAccessedTime()); %>
<br/>

<% out.println(session.getMaxInactiveInterval()); %>
</center></h2>

<jsp:directive.include file="JSP1.jsp"/>
<jsp:directive.include file="wel.txt"/>

</body>
</html>

Simple JSP, Declaration, expression, control structures


<!-- JSP -->

<html>
<body>
<h2><center>

<% out.println("HELLO WORLD"); %>
<br/>

<jsp:scriptlet>
     out.println("HELLO IT");
</jsp:scriptlet>
<br/>

<jsp:declaration>
     int a=2, b=3;
     int c=5;
     int x, f=1;
</jsp:declaration>

<jsp:scriptlet>
     x=a*b*c;
     out.println("x = "+x);
</jsp:scriptlet>

<br/>
<%= a*a*a %>
<br/>


<%
if (x%2==0)
{
     out.println("EVEN");
}
else
{
     out.println("ODD");
}
%>
<br/>

<%
for( int i=1;i<5;i++)
{
     f = f*i;
}
out.println("factorial = "+f);
%>
<br/>

</center></h2>

</body>
</html>

JSP Programs -- Page attributes


<!-- page attributes -->

<html>
<head><title>Hello World</title></head>
<body>
     <h2>
          <%@ page import="java.util.*" %>
          <%= (new Date()).toLocaleString()%>
          <br/>
          <%= request.getRemoteAddr() %>
          <br/>
          <%= session.getCreationTime() %>
          </h2>
</body>
</html>