Follow us on Facebook

Header Ads

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Welcome to JAVA POint

SERVLET IN JAVA

                                  *********SERVLET IN JAVA*************

-          Servlet technology is used to create a web application (resides at server side and                         generates a dynamic web page).

-          What is a Servlet?

-          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.

Methods of GenericServlet Class:                                                          

  • public void init(ServletConfig)
  • public abstract void service(ServletRequest request,ServletResponse response)
  • public void destroy()
  • public ServletConfig getServletConfig()
  • public String getServletInfo()
  • Public String getInitParameterNames()

HTTPServlet  Class:

-          It is also an abstract class.

-          This class gives implementation of various service() methods of Servlet interface.

-          To create a servlet,we should create a class that extends HTTPServlet class.

-          The servlet class must not override service().

-          It will override only doGet() and doPost().

The service() method listens to Http methods (GET,POST) from request stream and invokes doGet() and doPost() methods based on Http method type




It extend 

2.Handling HTTPResponse:

-          Servlet API provides two important interfaces ServletResponse and HttpServletREsponse to assist in sending response to client.

-          The HttpServletResponse interface enables a servlet to formulate an HTTP response to a client.javax.servlet.HttpServlet

-          Have in-built HTTP protocol support and are

more  useful in a Sun Java System web server.

-          For both servlet types,you implement the

constructor init() and the destructor destroy() to initialize or deallocate resources.

-          All  servlet must implement a service() method,which is responsible for handling servlet requests.

-          HTTP servlet provide a service method method  that automatically routes the request to another method .

-          Http  servlet override doGet() to process GET requests and doPost() to process POST request

-          HTTP servlet is HTTP protocol specific .


Life Cycle of a Servlet (Servlet Life Cycle):

       Servlet class is loaded

       Servlet instance is created

       init() method is invoked

       service() method is invoked

       destroy() method is invoked

       The web container maintains the life cycle of a servlet instance. Let's see the life cycle of the servlet:



Methods of servlets

 

1)      init() Method

public  void init(ServletConfig config) throws ServletException

-called only once.

-          It is called only when the servlet is created.

-          it is used for one-time initializations.

2) service() Method

public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { }

-is the main method to perform the actual task. The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client.

The doGet() and doPost() are most frequently used methods with in each service request.


a)doGet() Method

       A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Servlet code }

b)doPost() Method

       A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Servlet code}

3) destroy() Method

-          The destroy() method is called only once at the end of the life cycle of a servlet.

-          This method gives your servlet a chance to close database connections, halt background threads, write cookie lists or hit counts to disk, and perform other such cleanup activities.

       After the destroy() method is called, the servlet object is marked for garbage collection. The destroy method definition looks like this −

public void destroy() { // Finalization code... 


Simple servlet program:

HelloServlet.java

import java.io.*;

import  javax.servlet.*;

public class HelloServlet extends GenericServlet

{

                public void service(ServletRequest request,ServletErsponse response) throws ServletException,IOException

      {

                                response.setContentType(“text/html”);

                                PrintWriter pw= response.getWriter();

                                pw.println(“<B> Hello!”);

                                pw.close();

                }

}


Handling HTTPRequest and HTTPResponse

  1. Handling HTTPRequest:

-          When a browser requests for a web page, it sends lot of information  to the web server which cannot be read directly because this information travel as a part of header of HTTP request.

Methods

Descritption

String  getContextPath()

This  method returns the portion of the request URL that indicates the context of the request.

Cookies getCookies()

This method return an array containing all of the Cookie objects the client sent with this request.

String getQueryString()

Returns the query string that is contained in the request URL after the path.

HttpSession getSession()

Returns the current HttpSession associated with this request

String getMethod()

Returns the name of the HTTP method with which this request was made ,e.g. GET,POST,

Part getPart(String name)

Gets the Part with the given name.

String getPathInfo()

Returns any extra path information associated with URL the client sent when it made this request.

String getServletPath()

Returns the part of this requests URL that calls the servlet.

 2.Handling HTTPResponse:

-          Servlet API provides two important interfaces ServletResponse and HttpServletREsponse to assist in sending response to client.

-          The HttpServletResponse interface enables a servlet to formulate an HTTP response to a client.


Methods

Description

void addCookie(Cookie cookie)

Method adds the specified cookie to the response

void sendRedirect(String location)

Sends a temporary redirest response to the client using the specified redirect location URL and clears the buffer

int getStatus()

Gets the current status code of this response.

String getHeader(String name)

Gets the value of the response header with the given name.

void setHeader(String name,String value)

sets a response header with the given name and value.

void setStatus(int sc)

Sets the status code for this response.

void sendError(int sc,String msg)

Sends an error response to the client using the specified status and clears the buffer.

 



Software Devlopmnet Engineers off-Campus Internship

Software Devlopment Engineers  off-Campus Internship

DESCRIPTION

The SDE Intern experience is a unique at Amazon. You get to rub shoulders with outstanding software engineers and researchers with industry leading technical abilities, solving challenging engineering problems that affect millions of Amazon customers. You also get to collaborate and work with teams across the globe, in the process being exposed to a range of technologies, best practices and solution patterns. The Role: SDE Intern will be part of Device OS Organization and will be responsible for developing features for FireOS. Fire OS (based on Android) is used across a wide family of Amazon devices including Tablets, TV and exciting new array of products that are under development. This full time position requires candidates with good experience in C++/Java, Linux internals and preferably Android. In addition, the position will require very good analytical and problem solving skills. 
 


  BASIC QUALIFICATIONS:


Programming experience with at least one modern language such as Java, C++, or C# including object-oriented design · Self-driven, quick starters, passionate problem solvers with curious mind who love solving very complex, very challenging real world problems · Strong coding skills (e.g Java, C/C++ and/or other languages such as Python, Shell script, Ruby) · Solid fundamentals in Data Structure & Algorithm · Excited with opportunities to solve very complex problems and willingness to learn · Ability to think abstractly & deal with ambiguous problems · Willing to own all stages of development process: requirements, design, implementation, testing, and operational support · Ability to effectively articulate technical challenges and solutions · Excellent interpersonal communication with strong reading / written English skills. PREFERRED QUALIFICATIONS Major in Computer Science · Experience with UNIX/Linux environment · Have technical internship experience


. CLICK HERE TO APPLY: https://www.amazon.jobs/en/jobs/1090103/sde-intern


Join Telegram Channel Click Here Daily Jobs Update:Software Devlopmnet Engineers  off-Campus Internship

C language and C++ progaming