• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » JSP » JSP Session

Jsp getStatus Example

By Dinesh Thakur

In this example we will explain the get status method() this method is referred  to HttpServletResponse interface. The status we set will be diaplayed.

 

For example in the program we make a demo like to get status with domain name (web sites).here we also made two form first as designing page of demo example and the second one is to show all the criteria it does on the condition. let’s take a look…..

<html>

<head>

<style>

.label        {

                      font-family:”Palatino Linotype”, “Book Antiqua”, Palatino, serif;

                      font-size:14px;

                      color:#0e0e0e;

                 }

.border   {

                     border:solid 2px #0448e0;

                     margin-top:70px;

                }

.text        {

                        font-family:”MS Serif”, “New York”, serif;

                        font-size:16px;

                        color:#070200;

                }

</style>

   <title>status</title>

   </head>

   <body>

         <form action=”JavaExampleJSP_getStatus.jsp” method=”get”>

         <table cellpadding=”2px” cellspacing=”1px” bgcolor=”#F4F5F7″ width=”400px” class=”border” align=”center”>

         <tr>

           <td colspan=”2″ bgcolor=”#0066FF”>&nbsp;</td>

         </tr>

         <tr>

            <td colspan=”2″ class=”label”>&nbsp;</td>

        </tr>

        <tr>

           <td align=”center” colspan=”2″>

                 <span class=”text”><b>Enter Contents</b></span>

           </td>

        </tr>          

        <tr>

             <td colspan=”2″ class=”label”>&nbsp;</td>

        </tr>

        <tr>

            <td class=”label” align=”right” width=”50%”><b>Enter Web Site Name:</b>

            <br>(eg. google,yahoo)</br></td>

             <td align=”left” width=”50%”><input type=”text” name=”ws” maxlength=”20″/></td>

        </tr>

         <tr>

              <td class=”label” align=”right” width=”50″><b>Enter Domain Name:</b>

              <br>(like in,org,com)</br></td>

             <td align=”left” width=”50″><input type=”text” name=”dn” maxlength=”20″ /></td>

         </tr>

         <tr>

             <td class=”label” align=”right”>&nbsp;</td>

             <td align=”left”><input type=”submit” value=”Submit” /></td>

         </tr>                 

         <tr>

             <td colspan=”2″ class=”label”>&nbsp;</td>

         </tr>             

         </table>

         </form>

         </body>

         </html>

             Jsp getStatus Example

getStatus.jsp                                                                      

 <%@ page import=”java.net.URL, java.util.*” %>

<html>

    <head>

         <title>&lt;getStatus&gt; In JSP</title>

   </head>

  <body>

   <%

          String web = request.getParameter(“ws”);

          String domain = request.getParameter(“dn”);

          URL Nwurl = new URL(“http://”+web+”.”+domain);

          String url = Nwurl.toString();

          If(web != null)

           {

                response.setStatus(response.SC_MOVED_TEMPORARILY);

                response.setHeader(“Location”, url);

           }

    %>

      </body>

      </html>

        Jsp getStatus Example

Jsp setDateHeader Example

By Dinesh Thakur

This example will explain that the HttpServletResponse setDateHeader() method is used to set date with header name.in the example we use util package that will allow us to access the mandatory library for date initializing on the web browser as output.

<%@ page import=”java.util.*” %>

<html>

<head>

     <title>&lt;dateHeader&gt;In Jsp</title>

</head>

     <body>

     <center><br><b>

     <%

       long dt = new Date().getTime();

       response.setDateHeader(“Date”, dt);

       out.println(“Date is : “+response.getHeader(“Date”));

     %></b></center></br>

     </body>

     </html> 

         Jsp setDateHeader Example

Jsp headerRequest Example

By Dinesh Thakur

Header Request is a request information that the user make request to the server. This will display the header information like local host name, request path, query generation. Here we made a program that will demonstrate the header information with as output on the web browser. Some packages like enumeration also declared for coding.

<%@ page import=”java.util.Enumeration” %>

<html>

<head>

     <title>&lt;Header Request In JSP&gt;</title>

</head>

   <body bgcolor=”#F3EDE9″>

  <table border=”1″ align=”center” cellpadding=”2px” cellspacing=”2px  align=”center”>

   <tr>

        

         <span><h2 align=”center”>Header’s Request info</h2></span>

   </tr>  

         <%! Enumeration en, hdr;

              String hdrname, hdrvl;

         %>

         <%

             en = request.getHeaderNames();

             while (en.hasMoreElements())

              {

                   hdrname = (String) en.nextElement();

                   hdr = request.getHeaders(hdrname);

                   if(hdr != null)

                     {

                          while(hdr.hasMoreElements())

                          {

                              hdrvl= (String) hdr.nextElement();

                          }

                    }

         %>

         <tr>

            <td align=”center” ><%= hdrname %></td>

           <td align=”center”><%= hdrvl %></td>

        </tr>

           <%

        }

   %>

   </table>

  </body>

  </html>

        Jsp headerRequest Example

HTTP Session with Cookies

By Dinesh Thakur

HttpSession object allocates memory on the server and remembers client data across the multiple requests in the form of session attribute values. HttpSession object is one per browser window (client) so each HttpSession object can be used to remember client data during a session. [Read more…] about HTTP Session with Cookies

HTTP Session with Url Rewriting

By Dinesh Thakur

• The limitation with third technique is, if cookies are restricted from coming to browser then third technique fails to perform session tracking because it uses in memory cookie to send session id to browser from web application along with response and to bring session id to web application from browser window along with request. [Read more…] about HTTP Session with Url Rewriting

HTTP COOKIES in JSP

By Dinesh Thakur

Cookies are the small textual information which allocate the memory at client side by remembering client data across the multiple requests during a session. The web resource programs of web application create cookies at server side but these cookies come to client side along with the response and allocate memory at client side. Cookies of client side go back to their web application along with the request given by clients (browser windows to web resource programs). [Read more…] about HTTP COOKIES in JSP

What is Session Tracking?

By Dinesh Thakur

The form page prepared using .html file is called source form page (fixed content).The form page that comes as response generated by servlet or JSP program is called dynamic form page (dynamic content). Instead of asking all the details of end user in a single form page, it is recommended to ask those details in multiple form pages.

However, one big problem with it is that, the details entered in a particular form page cannot be accessed or retrieved in any other or even in the successive pages, because HTTP is a stateless protocol. This means every time a client sends a request a new connection is established and the previous request data lost. For example, in online shopping when we want to add a number of items to our cart, the online store’s server have to make a record of the items which will be used during purchase. This is where session tracking comes to play. Session tracking is tracking of client data throughout the session and across the form pages.

Figure shows static form page that the end user needs to read and answer some unnecessary question, when he selects or deselects the marital status checkbox. To overcome the problem, the working with dynamic form page is shown.

In Figure the content of form page2 is dynamic and generated by Srv1 program based on the marital status value of —– or request1 data.

All web applications are stateless web applications by default, which means —- cannot remember client data across the multiple requests during a session.

                    Bad Designed Form Page

                     Working with Dynamic Form Page

A session is a set of continuous and related operations (requests) — on the web application by a client (browser window / end user).

By stateless behavior of web application we mean that while processing current request in any web resource program, we cannot use previous request data, which means while processing request2 we cannot use request2 data as shown in Figure.

Web applications are stateless because the protocol http is given as stateless protocol. According to this, one new connection will be created between browser window and web server for every request and this connection will be closed automatically, once related response goes to the browser window.

Example

If browser window gives 10 requests to a web application, 10 connections will be created between browser window and web server. Due to this one connection related to a client’s request data cannot be used in an other connection related to the client’s request processing (that means we cannot use previous request data in web resource program while processing current request).

By placing <form> tag, <input> tag in pw.println( ) statements of servlet program we can generated dynamic form page from that servlet program. In naukri.com registration process multiple forms will be there. The first form page is static form page and other form pages are dynamic form pages. Based on the data given in form page1 the questions in form page2 will be rendered. Similarly, based on data in form page2 the questions in form page3 will be rendered.

Web applications are stateless because they are using a stateless protocol called.

Hidden Form Fields in JSP

By Dinesh Thakur

An invisible text box of the form page is called a hidden box. When a form page is submitted, the hidden box value goes to web resource program along with the request parameter value. [Read more…] about Hidden Form Fields in JSP

HTTP is a Stateless Protocol

By Dinesh Thakur

We will discuss why HTTP is designed as a stateless protocol and what will happen if it comes as stateful protocol. If HTTP is stateful protocol, multiple requests given by client to web application by a single connection will be used between browser window and web server across the multiple requests. This makes clients engage connection with web server for long time even though most of its connections are idle.

To overcome that problem, HTTP is given as stateless so that no client can engage connection with web server for a long time. Moreover, the connection will be closed automatically at the end of each request related to response generation. In the Internet environment since there is a chance of having huge amount of clients for each website it is recommended to have stateless behavior for http.

If web application is capable of remembering a client data during a session across the multiple requests, then that web application is called a stateful web application. In stateful web applications the web resource programs can use the data of previous request, while processing current request, that is while processing request2, it can use request1 data.

Even though HTTP is a stateless protocol we need to make our web applications stateful. For this we need to work with the following session tracking or session management techniques:

(1) Hidden form fields

(2) HTTP cookies

(3) HTTP session with cookies

(4) HTTP session with URL rewriting (recommended)

Session tracking/ session management is all about making web applications stateful by remembering client data across the multiple requests during a session

Primary Sidebar

Java Server Pages

Java Server Pages

  • JSP - Home
  • JSP - Advantages
  • JSP - Architecture
  • JSP - Life Cycle
  • JSP - Servlet Disadvantages
  • JSP - PrintWriter Vs JspWriter
  • JSP - Session Tracking
  • JSP - Stateless Protocol
  • JSP - Hidden Form Fields
  • JSP - Program Structure
  • JSP - Bill Discount Program
  • JSP - Scripting Elements
  • JSP - fn:length()
  • JSP - fn:split()
  • JSP - fmt formatNumber Tag
  • JSP - Servlet Communication
  • JSP - fn:replace()
  • JSP - fmt:parseNumber Tag
  • JSP - fmt:parseDate Tag
  • JSP - fn:substring()

Other Links

  • JSP - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW