JSP and Servlets

Vidumini Bandara
6 min readSep 25, 2022

HTTP request methods and usages of them

HTTP is the short form of HyperText Transfer Protocol. It is the foundation of the WWW which denotes the worldwide web. This is used to load web pages using hypertext links and also transfer information between networked devices and runs on top of other layers of the network protocol stack as an application layer protocol. HTTP is used when a web browser asks for information, they need to load a website. It means the way internet communication platforms. The 8 types of HTTP request methods are as follows,

  • GET — Used to retrieve information using a given URI from the relevant server. Simply it’s reading. There should not be any other effect occurring on the data taken by this method.
  • POST — Used to create and send data to the server.
  • PUT — Updates and replacements are done. Replaces all current representations with the uploaded content of the relevant resource.
  • DELETE — Removes all the current representing information given by the URI, in the relevant resource.
  • PATCH — Update and modify information on the relevant server.
  • CONNECT — Establish a tunnel by a given URI to the server.
  • HEAD — The same kind of job as the get method do. But only transfer the header section and status line.
  • TRACE — Carry out a Message loop backtest through the path to the relevant resource.
  • OPTIONS — Explains the communication option for the relevant resource.

Session Management

The purpose of session management is to support secure interactions between a service or application and a user and applies to that user-related sequence of requests and responses. When a user has a continuous session with a web application, they make requests during their session and can often provide sensitive information. The relevant app can retain this information and monitor the user’s status during the session through various requests. Most of all, it is extremely important for the relevant app to have a personal data protection app that is unique to each user, especially during authentication sessions.

Web Application

A web application is a software that runs on a web server, rather than the other computer-based software programs that are in the device’s Operating system. But it’s application software. These are designed and programmed based on the client-server model. It actually means the off-site server hosted by a third party is providing service for the client or the user. When accessing web applications through a web browser we need an active internet connection. Online banking and webmails are some of the examples of the web applications which we use.

Web Sites

A website is a central location or a collection of web pages that are identified using a single domain name that is declared on at least one web server. All websites that are publicly accessible are collectively comprised of the World Wide Web. Some companies have internal websites for their employees. So, other than public websites, private websites that can only be accessed by a private network also exists. Websites are usually devoted to a specific topic or to a special purpose, such as education, economics, news, climate, marketing, social media, or entertainment.

Web Applications Vs. Web Sites

Filter and Filter Chaining

JSP filters are Java classes that can be used to block client requests or to handle client responses. Filters can be used for authentication, logging, auditing, and encryption. These filters are operating in the order in which they are published in the Deployment Description. In web.xml in the application deployment details files, we can filter maps to JSP names or URL patterns. doFilter(), init() and void destroy() are the three methods of filters in the javax.servlet.Filter interface.

Filters are classified in various ways. It actually doesn’t have a fixed classification according to a hierarchy. Filters may be, time-variant or time-invariant, non-linear or linear, casual or not casual, analog or digital, discrete-time or continuous time, infinite impulse response, or finite impulsive response.

A filter chain is an object provided by the server directory to the developer, giving a view of the appeal chain in a filtered request for a resource. The filter uses the filter chain to call the next filter in the chain or to request the resource at the end of the chain if the call filter is the last filter in the chain.

Uses of Listeners

The interface responsible to handle events is represented by event listeners. User Interface listener is a method that the user who does something that the programmer must notify. The listener method has adopted an event parameter that can tell something about what has happened. Events and listeners are widely used in the user interface, but they have the ability to communicate between other sources or other parts of a program. Each mode of event listening has a single argument as an object that is a subclass of the Event Object class. There are 10 listeners which are focused on the following purposes,

  • Action listener — Receiving the action events.
  • Item listener — receiving the item events.
  • Component listeners — receiving the component events.
  • Mouse listener — receiving the mouse events.
  • Key listener — receiving the key events.
  • Window listener — receiving the window events.
  • Mouse Motion listener — receiving the mouse motion events.
  • Focus listener — receiving the focus events.
  • Adjustment listener — receiving the adjustment events.

Wrappers in Servlets

Servlet wrappers are used to wrap requests and responses. A pattern where we enhance the functionality of existing classes is provided by this wrapper. Mainly there are 2 types of wrappers. They are request wrappers and response wrappers. Again, they will divide into servlets and http servlets as follows,

  • javax.servlet.ServletRequestWrapper — wrap servlet request.
  • javax.servlet.ServletResponseWrapper — wrap servlet response.
  • javax.servlet.HttpServletRequestWrapper — wrap Http servlet request.
  • javax.servlet.HttpServletResponseWrapper — wrap Http servlet response

Using the above wrapper classes, we can validate requests, add more data or change data to the response object and before requests reach the requested servlet, we can add more data or change data. When creating a request servlet, filter classes are associated with them.

Importance of handling exceptions in global level web applications

Runtime errors that occur in an application are simply known as exceptions. The running programs will terminate, crash or the requests may fail if the expectations are not handled properly. So, handling these expectations are important in global-level web applications. These expectation handlers are the error handlers that detect errors and do corrections. And also Maintain a normal, expected flow of the program even when unforeseen events occur. By using a global exception handler, we can ensure that exceptions are captured without any control. There may be hardware or software exceptions.

💻👩‍💻👨‍💻💻👩‍💻👨‍💻💻👩‍💻👨‍💻💻👩‍💻👨‍💻💻👩‍💻👨‍💻💻👩‍💻👨‍💻💻👩‍💻👨‍💻💻

Let me wind up this topic here. I look forward to seeing you soon with another interesting topic. See you soon!!

Have a wonderful day! Take care!

--

--

Vidumini Bandara

Software Quality Assurance Engineer | Undergraduate | Faculty of Information technology, University of Moratuwa | Intern — Software Engineer | Josephian