Tuesday 26 March 2013

web applications and basics



web applications and basics:



HTML:
ü              HyperText Markup Language (HTML) is the main markup language for creating web pages and other information that can be displayed in a web browser.
HTTP:
ü             The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative,  hypermedia information systems.
ü             HTTP is the foundation of data communication for the World Wide Web.

Web container:
Web container (also known as a Servlet container) is the component of a web server that interacts with Java servlets.

ü       A web container is responsible for managing the lifecycle of servlets, mapping an URL to a particular servlet and ensuring that the URL requester has the correct access rights.

ü     A web container implements the web component contract of the Java EE architecture, specifying a runtime environment for web components that includes security, concurrency, lifecycle management, transaction, deployment, and other services.

ü     A web container provides the same services as a JSP container as well as a federated view of the Java EE platform APIs.






What is a web applications?

ü     An obvious but still accurate definition of a web application is that it is an application is accessible from the web!
ü      A common example of a web application is a web site that provides free e-mail service.

ü      It offers all the features of an e-mail client such as outlook express but is completely web based.

ü     A key benefit of web applications is the case with which the users can access the applications.

ü     All a user needs is a browser there is nothing else to be installed on the user’s machine.

ü  This increases the reach of the applications tremendously while alleviating versioning and upgrading issues. 

ü  a web applications is built of web components that perform specific tasks and are able to expose their services over the web.

ü  all of these components coordinate with one another and provide a complete set of services users.

Active and passive resources:

ü  one way of categorizing web resources is that they are either passive or active.

ü    a resources is passive when it does not have any processing of its own active objects have their own processing capabilities.
for example when a browser sends a request for www.myserver.com/myfile.html.

ü    The web server at my server.com looks for the myfile.html file, a  passive resources, and return it to the browser.  Similarly when a browser sends a request for www.myserver.com/report servlet,the web server at myserver.com forwards the request to report servlet, an active resources.

ü    The servlet generates the html text on the fly and gives it to the web server.
The web server ,in turn forwards it to the browser.

ü  a passive resources is also called a static resource since its contents do not change with requests.

ü  a web application is usually a mixture of active and passive resources. But it is the presence of the active resources that make web applications nearly as interactive as normal applications.


ü  Active resources in web applications typically provide dynamic content to users and enable them to execute business logic via their browsers.

Web application and the web application server:

ü  a web application resides in a web application server (or application server)
ü  the application server provides the web application with easy and managed access to the resources of the system.

Ex of Common template web technologies:



Servlet technologies:









hello world servlet example

hello world servlet example:                                                           by, madhav
















web.xml




     <servlet>
  <servlet-name>gmr</servlet-name>
  <servlet-class>madhav.SaiHaiResource</servlet-class>

  </servlet>

  <servlet-mapping>
  <servlet-name>gmr</servlet-name>
  <url-pattern>/hai</url-pattern>
  </servlet-mapping>
</web-app>



1)   once u develop a application, the container will create the instance of SaiHaiResource  and it call automatically init() method in it.

2)  if client made a request url like: http://localhost:8080/sayhai/hai

3)  than the container will check the url pattern, if is matching than will check appropriate
    servlet mapping name, and it creates new thread .

4)   the newly created thread will executed on service method on that servlet instance.  


SaiHaiResourc.java




package madhav;

import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SaiHaiResource extends HttpServlet{

       public void doGet(HttpServletRequest req,HttpServletResponse res)
       {
              try
              {
                     res.setContentType("text");
                     PrintWriter out=res.getWriter();
                     out.println("hai how r u");
              }
              catch(Exception e)
              {
                    
              }
       }
}
 


       public void doGet(HttpServletRequest req,HttpServletResponse res)


This is life cycle method available in HttpServlet  . call by the container after getting request, response objects from the server.

This two objects are created by the server by the time of requested by the client for a resource.

hear initially container call the servvice method,from their it wil call the doGet (), doPost() based on request method type.



output:











Note:

hear i am trying to call  a static resource available is server.


hai.html




<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hai  how r u?
</body>
</html>



If client made a request  like : http://localhost:8080/sayhai/hai.html


the server will automaticaly pick up that resource and send back to the client.


output: