Basics of Servlets and Deploying them on. (-Made Easy.)

Executing servlets in IDE(eg: Netbeans etc) is very easy because they automatically take care of deploying servlets on server. i instead recommend everyone to learn how to deploy at least one servlet on server .it gives you deep and clear understandng learning this way.


First download XAMPP it makes your life easy. I prefer tomcat for execution of servlets which comes with this software.

Servlet is similar to applet the main difference between both of them is             
  • Applet  - Runs on browser which is installed on client Machine.
  • Servlet - Runs on server.




What is Container and servlet Container?

Container is a general computer term which looks after the execution of a program. Following are the responsibilities of a container.
  • Responsible to call the callback methods whenever required for the smooth execution of the program.
  • Responsible to maintain the life cycle of the program (application).
Example: JVM is a Container which calls main method during start of execution.

Servlet container is responsible to execute the servlet. The callback methods called by the servlet container are init(), service() and destroy() (also known as life cycle methods). In our subsequent programs, we load Tomcat server which gets us the servlet container.

Client server communication:


  • In Web communication, the client and server uses Web (Internet) as an interface (medium) of communication. That is, both client and server should connect to Web (though an Internet Service Provider) to communicate, else, impossible to communicate

  • When connected, the client sends a request and server response

  • To send a request, the software to be loaded on the Web cleint is "Browser" (the same browser you use to connect to Internet). Similarly, the software required on the Web server is "Web server software". To get the Web server software (or servlet container), most commonly used server is Tomcat (of Apache), Weblogic (of BEA, now acquired by Oracle) and WebSphere (of IBM) etc.



Responsibilities of Web client:


  • Should be able to take request from the client by displaying some GUI environment(like user name and passowrd as in Login screen).
  • To extract the data entered by the user and send it to the Web server as request.
  • Should be able to receive what the server responses and display to the user.

Resposibilities of Web server:
  • Should be able to receive the request send by the Web client.
  • As per the request, load an appropriate servlet, execute it and send the output of execution as response to client.
  • When response is delivered close the connection.

On the Web server-side, I prefer to use popular Tomcat. Tomcat understands Servlets and JSP apart other frameworks like Struts. Servlets are written in Java as per Servlet API specifications (rules) stipulated by Sun Microsystems.

SERVLETS NOTES FOR EXECUTION IN PC:




STEPS:



1 - Set class path in enviornment variables:C:\xampp\tomcat\lib\servlet- api;C:\Program Files\Java\jdk1.8.0_60\lib(otherwise servlets java prog will not be compiled)



2 - Now go to C:\xampp\tomcat\webapps and create a new folder for practising servlets(eg:servlets prac)



3 - Now copy the web-inf folder present at -->C:\xampp\tomcat\webapps\servlets prac\WEB-INF to ur directory i.e (servlets parc in web apps folder)



4-Remember, now onwards when I talk about WEB-INF folder, I mean the WEB-INF available in your custom folder. Don't change anything in the main WEB-INF folder

5 - After compiling ur servlet java file put the obtained class file in C:\xampp\tomcat\webapps\servlets prac\WEB-INF\classes file [if classes file is not there create it.]

6 - In the web.xml file (present in web inf folder) add the following code just before </web-app> tag.
<servlet>
    <servlet-name>YourFileName</servlet-name>
    <servlet-class>YourFileName</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>YourFileName</servlet-name>
    <url-pattern>/YourFileName or some dummy name</url-pattern>
</servlet-mapping>

6- Now run tomcat server in xampp and execute the program.
I have done a project on servlets you can refer to this here:
This is done on netbeans so if you have idea how servlets execute on netbeans then you can refer this.










Comments

Popular posts from this blog

FC Barcelona vs Real Madrid -El Clasico Rivalry.

Different Type of keys in Database Managemenet System.

Normalization in Database.