Something I Know

خرید بک لینک

Well in this speech I want to talk about spring boot and everything it is necessary you know that.

What is a Servlet?

Servlet can be described in many ways, depending on the context.

  • Servlet is a technology which is used to create a web application.
  • Servlet is an API that provides many interfaces and classes including documentation.
  • Servlet is an interface that must be implemented for creating any Servlet.
  • Servlet is a class that extends the capabilities of the servers and responds to the incoming requests. It can respond to any requests.
  • Servlet is a web component that is deployed on the server to create a dynamic web page.

What is a web application?

A web application is an application accessible from the web. A web application is composed of web components like Servlet, JSP, Filter, etc. and other elements such as HTML, CSS, and JavaScript. The web components typically execute in Web Server and respond to the HTTP request.

CGI (Common Gateway Interface)

CGI technology enables the web server to call an exteal program and pass HTTP request information to the exteal program to process the request. For each request, it starts a new process.

Disadvantages of CGI

There are many problems in CGI technology:

  1. If the number of clients increases, it takes more time for sending the response.
  2. For each request, it starts a process, and the web server is limited to start processes.
  3. It uses platform dependent language e.g. C, C++, perl.

Advantages of Servlet

There are many advantages of Servlet over CGI. The web container creates threads for handling the multiple requests to the Servlet. Threads have many benefits over the Processes such as they share a common memory area, lightweight, cost of communication between the threads are low. The advantages of Servlet are as follows:

  1. Better performance: because it creates a thread for each request, not process.
  2. Portability: because it uses Java language.
  3. Robust: JVM manages Servlets, so we don't need to worry about the memory leak, garbage collection, etc.
  4. Secure: because it uses java language.

-What information is received by the web server if we request for a Servlet? When a request is made, the Sun Java System Web Server hands the incoming data to the servlet engine to process the request. The request includes form data, cookies, session information, and URL name-value pairs, all in a type HttpServletRequest object called the request object.

-What are the ways for servlet collaboration and what is the difference between RequestDispatcher and sendRedirect() method?The RequestDispatcher interface allows you to do a server side forward/include whereas sendRedirect() does a client side redirect.
SendRedirect() will search the content between the servers. it is slow because it has to intimate the browser by sending the URL of the content. then browser will create a new request for the content within the same server or in another one.
RquestDispatcher is for searching the content within the server i think. its the server side process and it is faster compare to the SendRedirect() method. but the thing is that it will not intimate the browser in which server it is searching the required date or content, neither it will not ask the browser to change the URL in URL tab. so it causes little inconvenience to the user.

What is the difference between ServletConfig and ServletContext interface? But, the difference lies in the fact that information shared by ServletConfig is for a specific servlet, while information shared by ServletContext is available for all servlets in the web application.

A filter is an object used to intercept the HTTP requests and responses of your application. By using filter, we can perform two operations at two instances −

  • Before sending the request to the controller
  • Before sending a response to the client.

The following code shows the sample code for a Servlet Filter implementation class with @Component aotation.


@Component

public class SimpleFilter implements Filter {

@Override

public void destroy() {}

@Override

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterchain)

throws IOException, ServletException {

System.out.println("Remote Host:"+request.getRemoteHost());

System.out.println("Remote Address:"+request.getRemoteAddr());

filterchain.doFilter(request, response);

}

@Override

public void init(FilterConfig filterconfig) throws ServletException {}

}

FilterChain:

A FilterChain is an object provided by the servlet container to the developer giving a view into the invocation chain of a filtered request for a resource. Filters use the FilterChain to invoke the next filter in the chain, or if the calling filter is the last filter in the chain, to invoke the resource at the end of the chain.

Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.

Params:

request – the request to pass along the chain.

response – the response to pass along the chain.

Throws:

IOException – if an I/O error occurs during the processing of the request

ServletException – if the processing fails for any other reason

+ نوشته شده در 2022/11/17 ساعت 8:53 توسط علیرضاابوالحسنی  | 

هم میهنان کورد زبانم تسلیت......

ما را در سایت هم میهنان کورد زبانم تسلیت... دنبال می‌کنید

برچسب: نویسنده: بازدید: 106 تاريخ: يکشنبه 9 بهمن 1401 ساعت: 9:29

صفحه بندی