WriteUp Computer Networks 1234
WriteUp Computer Networks 1234
or get the required Information. Broadly websites can be categorized into 2 categories One is Static websites and another one is Dynamic Websites Example of Static website is http://www.sgei.org while the example of Dynamic website is http://www.uptu.org
In the case of static websites who so ever is the user i.e. myself, you or any third party will always get the same web page whenever they access the website. In the case of dynamic websites the new page is generated always as per the requirement of the user. For example in the case of UPTU website when I will insert my roll number I will get my result and when you will insert your roll number, you will be able to access your result not mine Static websites can be building basically using HTML only as it supports text, audio and video basically required for static websites For building Dynamic websites we have broadly 2 technologies through which these can be created .One is Microsoft Technology which provides ASP, ASP DOT NET, VB DOT NET, C SHARP as a front end tool Another one is JAVA Technology, which provides Java Servlets and Java Server Pages (JSP) to build dynamic pages. For building the dynamic websites using Java technologies obviously we have to require a server on which we will keep our pages/class files. There are many servers available out of which any one can be used. For example Java Web Server, J2EE Server, BEA WEBLOGIC, Apache Tomcat Server. Java has provide another s/w which can be downloadable free of cost which is JAVA SERVLET DEVELOPMENT KIT (JSDK2.0) for creating servlets. JSDK will provide the same functionality as normal server and is just like a tool APPLETVIEWER.But it has one drawback (restriction of the port number). We have used Tomcat 4.1 which can be downloadable freely from the website http://apache.org
Servlets
Java servlets are small, platform independent server-side programs that programmatically extend the functionality of web server .The Java Servlet API provides a simple framework for building applications on such web servers. The Web server is extended to support an API, and then Java programs use the API to create dynamic web pages An alternate form of server-side computation that uses Java. Servlets can be embedded in many different servers because the servlet API, which you use to write servlets, assumes nothing about the server's environment or protocol.
HOW IT WORKS Read data send by the client (Form data) Generates the result. Send the data back to the client (HTML) ADVANTAGES Only a single copy of class file is loaded into memory. No need to learn new programming languages if you are familiar with Java already. Easy to implement Database connection. Provides an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions and other utilities Run on virtually all operating systems and servers
An HTTP servlet usually overrides doGet() to handle GETrequests and doPost() to handle POST request. The service () method of HttpServlet handles the setup and dispatching to all the doXXX() methods, which is why it usually should not be overridden. The servlet extends the HttpServlet class and overrides the doGet()method inherited from it. Each time the web server receives a GET request for this servlet, the server invokes this doGet() method, passing it an HttpServletRequest object and an HttpServletResponse object. The HttpServletRequest represents the clients request. This object gives a servlet access to information about the client, the parameters for this request, the HTTP headers passed along with the request, and so forth . The HttpServletResponse represents the servlets response. A servlet can use this object to return data to the client.
Servers Installation
Now the problem arises How to installation TOMCAT SERVER 4.1. What settings we have to make to work it properly. What port number we have to use . Other problems are where to write Servlet program. Where to store it .How to compile it and how to run it. ANSWERS 1. Use port number not used by any other service during installation of Tomcat Server. (Mind it you must have installed JDK1.4 or later version before installing TOMCAT server) 2. Use the following settings My ComputerAdvanceEnvironment Variablesadd 3 new system variables (if not already present) and give the values as follows CATALINA_HOME --- C:\Program Files\Apache Software Foundation\Tomcat 4.1 CLASSPATH --C:\j2sdk1.4.0_01\bin; %CATALINA_HOME%\common\lib\servlet.jar; JAVA_HOME--C:\j2sdk1.4.0_01 Path --%JAVA_HOME%\bin; %CATALINA_HOME%\bin;
COOKIES
Idea is servlet sends a simple name and value to the client. Client returns same name and value when it connects to same site. Cookie is a class in Java used to set a cookie on client side by server and to retrieve the information stored by server Typical uses of cookie Identify a user during E-commerce Session. Avoiding username and password customizing a site Focusing Advertising Why Cookies To transfer the information from one page to another, for example using shopping sites, or your name at mail.yahoo.com
So basically a cookie is a small amount of information sent by a Web server to a Web browser, saved by the browser, and sent back to the server later. Cookies are transmitted inside the HTTP header. Cookies move from server to browser, and back to server as follows: Web Web Local Web Web Server Browser System Browser Server Send Receive Save Send back Receive cookies --> cookies --> cookies --> cookies --> cookies As you can see from the diagram, cookies are actually saved to the hard disk of Web browser user's machines. Many users are concerned about this. But I think it is pretty safe to allow your browser to save cookies. If you are really concerned, you can change your browser's settings to reject cookies. But this may cause many Web based applications fail to run on your browser. Sending and Receiving Cookies
Sending cookies to the browser can be done by the addCookie() method on the response object; while receiving cookies from the browser can be done by the getCookies() method on the request object.
Persistent Cookies
A persistent cookie is one stored as a file on your computer, and it remains there when you close Internet Explorer. The cookie can be read by the Web site that created it when you visit that site again. You can use cookie.setMaxAge(s) to set the cookie to be persistent for 's' seconds. A temporary or session cookie is stored only for your current browsing session, and is deleted from your computer when you close Internet Explorer. You can use cookie.setMaxAge(-1) to set the cookie to be temporary. Other properties of a cookie object that you can set and get:
setPath(): Defines the path name so that when a pages under this path name is requested, the browser will send this cookie to the server. The path name is the url without the server name and the port number parts. setDomain(): Defines the domain name so that when a page under this domain name is requested, the browser will send this cookie to the server. The default domain name is the server name from which the cookie was created. setMaxAge(): Defines how long the cookie should be stored on the browser's machine. MaxAge value is in unit of second. A negative value tells the browser to not save it to the harddisk. A zero value tells the browser to delete it. setVersion(): Defines the version number to which this cookie is compliant with
Conclusion
Cookie is a piece of information the server is asking client the pass it back on the next request. Cookie is best way to link multiple requests into a "session". Cookies are generally safe to accept. Persistent cookies are stored as files on client system. Cookies are passed in HTTP request and response header section. Setting and receiving cookies are easy to do in JSP pages.
JSP source Code (.jsp file) Java Source Code (.java file) Compiled Java File (.class file) JSP Source code Generated Servlet Source Code Compiled servlet class User is totally unaware of these changes /transparent to the user
10
11
12