Tuesday, August 30, 2005

Make others find your blog by location

Today I found an interesting website - GeoURL, all thanx to this blog. It is a location-to-URL reverse directory and allows you to find URLs by their proximity to a given location.

It is very easy to get a "GeoURL".

  1. Find the longitude and latitude of the blogs location

  2. Insert some metatags in the head of your webpage, my metatags is as following



  3. <meta name="ICBM" content="28.662, 77.106"/>
    <meta name="DC.title" content="Raj Blogs"/>
    <meta name="geo.position" content="28.662, 77.106"/>



  4. Register with GeoURL by using its ping form or a GET query something like this:


  5. Finally insert the HTML code generated by GeoURL into your webpage.

Find your neighbor's blog :-)

Wednesday, August 24, 2005

Google Desktop 2 and Talk

I have just installed Google Desktop 2 on my office workstation and hope to install it on my home machine later in the evening.
After installation, it is indexing the files. The 'sidebar' feature seems quite good, but Weather and Share Market info is meant only for those in US :( A big disappointment for us non-US people.
What u say of it? Any reviews?

Also, I plan to install Talk on my home machine. How it it. Has anybody used it so far? Any reviews?

What is XMLHTTP

XMLHTTP is Extensible Markup Language Hypertext Transfer Protocol. It is a set ofAPIs that enables XML, HTML or binary data to be transmitted to and fromWeb servers over the Internet using HTTP.
An advantage of XMLHTTP is that when files that are User Interface programs (e.g. JSPs, ASPs or CGI programs) are queried from the server, theXMLHTTP object continuously queries the server transparently to retrievethe latest information without the user having to repeatedly refresh thebrowser. XMLHTTP enables streamed content through DHMTL rather than ActiveXcontrols or Java applets.

Source: Webopedia.com
Userful Links: Define XMLHTTP Google XMLHTTP

Blog Subscription by Email

I have introduced email based subscription for the Blog, all thanx to Bloglet. The subscription option is available in the left sidebar :-)

Monday, August 22, 2005

JSP Model 1, Model 2 Architectures and MVC Pattern


JSP Model 1, Model 2 Architectures and MVC Pattern
The early JSP specifications presented two approaches for building web applications using JSP technology. These two approaches were the JSP Model 1 and Model 2 architectures. The two JSP architectures differ in several key areas.
The major difference is in how and by which component the processing of a request is handled. With the Model 1 architecture, the JSP page handles all of the processing of the request and is responsible for displaying the output to the client. There is no extra servlet involved in the process. The client request is sent directly to a JSP page, which may communicate with JavaBeans or other services, but ultimately the JSP page selects the next page for the client. The next view is determined based on either the JSP selected or parameters within the client's request. In contrast, in the Model 2 architecture, the client request is first intercepted by a servlet, referred to as a controller servlet. This servlet handles the initial processing of the request and determines which JSP page to display next.A client never sends a request directly to a JSP page in the Model 2 architecture. This allows the servlet to perform front-end processing, including authentication and authorization, centralized logging, and help with internationalization. Once request processing has completed, the servlet directs the request to the appropriate JSP page. How the next page is determined varies widely across different applications. The main difference between the two approaches is that the Model 2 architecture introduces a controller servlet that provides a single point of entry and encourages more reuse and extensibility than the Model 1 approach. With the Model 2 architecture, there is a clear separation of the business logic, presentation output, and request processing. This separation often is referred to as a Model-View-Controller (MVC) pattern.

While the Model 2 architecture might seem overly complicated, it actually can simplify an application greatly. Web applications built using the Model 2 approach generally are easier to maintain and can be more extensible than comparable applicationsbuilt around the Model 1 architecture.

Importance of Model-View-Controller

The MVC architectural pattern is not directly related to web applications. In fact, it's quite common in Smalltalk applications, which generally have nothing to do with the Web.
The Model 2 approach is concerned with separating responsibilities in web applications. Allowing a JSP page to handle the responsibilities of receiving the request, executing some business logic, and then determining the next view to display can make for an unattractive JSP page, not to mention the maintenance and extensibility problems this entanglement causes. Application development and maintenance are much easier if the different components of a web application have clear and distinct responsibilities.

The MVC Model
Depending on the type of architecture your application uses, the model portion of the MVC pattern can take many different forms. In a two-tier application, where the web tier interacts directly with a data store such as a database, the model classes may be a set of regular Java objects. These objects may be populated manually from a ResultSet returned by a database query, or they may be instantiated and populated automatically by an object-to-relational mapping (ORM) framework such as TopLink or CocoBase.

The MVC View
The views within the web tier MVC pattern typically consist of HTML and JSP pages. HTML pages are used to serve static content, while JSP pages can be used to serve both static and dynamic content.
Most dynamic content is generated in the web tier. However, some applications may require clientside JavaScript. This does not interfere with or infringe upon the MVC concept.
HTML and JSP are not the only choice for the view. You easily can support WML, for example,
instead of HTML. Because the view is decoupled from the model, you can support multiple views, each for a different client type, using the same model components.

The MVC Controller
The controller portion of the web tier MVC design generally is a Java servlet. The controller in a web tier application performs the following duties:

  • Intercepts HTTP requests from a client
  • Translates each request into a specific business operation to perform
  • Either invokes the business operation itself or delegates it to a handler
  • Helps to select the next view to display to the client
  • Returns the view to the client

    The Front Controller pattern describes how a web tier controller should be implemented. Because all client requests and responses go through the controller, there is a centralized point of control for the web application. This helps when adding new functionality. Code that would normally need to be put in every JSP page can be put in the controller servlet, which processes all the requests. The controller also helps to decouple the presentation components (views) from the business operations, further aiding development.

    Useful Links : Sun's Patterns Catalog Front Controller Pattern

  • Here is a graphical repersentation of a typical struts based application.

    Click to view larger image


    Sunday, August 21, 2005

    JSP Performance Tips

    Here are a few tips to improve JSP performance that I have been using. If you have your own listing of the tips, plz share.

  • Disable JSP auto reloading feature.
  • Use thread pool for your JSP engine and define the size of thread pool as per application requirement.
  • Use jspInit() method to cache static data
  • Initialize the 'out' object (implicit object) with proper size in the page directive.
  • Set the content length
  • Give 'false' value to the session in the page directive to avoid session object creation.
  • Flush the data partly
  • Use StringBuffer rather than using + operator when you concatenate multiple strings
  • Use include directive instead of include action when you want to include the child page content in the translation phase.
  • Avoid giving unnecessary scope in the 'useBean' action.
  • Use print() method rather than println() method
  • Use ServletOutputStream instead of JSPWriter to send binary data
  • Minimize code in the synchronized block
  • Do not use custom tags if you do not have reusability.
  • Use 'session' and 'application' as cache.
  • Remove 'session' objects explicitly in your program whenever you finish the task
  • Use caching tags provided by different organizations like openSymphony.com
  • Reduce session time out value as much as possible
  • Release resources in jspDestroy() method.
        • Thursday, August 18, 2005

          [Updated] JDBC Drivers

          I have updated my earlier post on JDBC Drivers. Updated version can be viewed here.

          [Humor] Being an IT Consultant

          Once upon a time there was a shepherd sitting on the side of a deserted road. Suddenly a brand new Porsche screeches to a halt. The driver, a man dressed in an Armani suit, Cerutti shoes, Ray-Ban sunglasses, TAG-Heuer wrist-watch, and a Pierre Cardin tie, gets out and asks the Shepherd: "If I can tell you how many sheep you have, will you give me one of them?"

          The shepherd looks at the young man, and then looks at the large flock of grazing sheep and replies: "Okay."

          The young man parks the car, connects his laptop to the mobile-fax, enters a NASA Webster, scans the ground using his GPS, opens a database and 60 Excel tables filled with logarithms and pivot tables, then prints out a 150 page report on his high-tech mini-printer. He turns to the shepherd and says, "You have exactly 1,586 sheep here."

          The shepherd cheers," That's correct, you can have your sheep."

          The young man makes his pick and puts it in the back of his Porsche.

          The shepherd looks at him and asks:"If I guess your profession, will you return my animal to me?"

          The young man answers, "Yes, why not". The shepherd says, "You are an IT consultant ".

          How did you know?" asks the young man.

          "Very simple," answers the shepherd. "First, you came here without being called. Second, you charged me a fee to tell me something I already knew,and third, you don't understand anything about my business... Now can I have my DOG back?"

          Servlets Vs Applets

          There are some things to note to note about Servlets as opposed to Applets.

          Firstly, the servlet and its environment is completely under the control of those deploying it. That is, you have control of which JVM is used and that this is independent of the browser used by the user. This is important as it removes concerns associated with the so-called “browser” wars.
          Secondly, a servlet is not constrained by the applet sandbox. This means that a servlet can reside behind a firewall and can communicate with any and all systems that it needs to. For example, JavaIDL can be used to connected to a CORBA compliant Object Request Broker (ORB) or sockets to connect to legacy systems (for example implemented in C).
          Thirdly, the client Web browser does not communicate directly with the servlet. Rather the browser communicates with the Web server, which in turn communicates with the servlet. Thus if the web server is secure behind a firewall, then the servlet is also secure.
          Fourthly a single Servlet can process multiple user requests. That is one instance (by default) of a Servlet is loaded into the web server and this instance services all user requests. This does not mean that each request is queued. Rather it means that each request is handled by a separate thread (of execution) that uses the same servlet instance.
          Fifthly, as each Servlet is shared amongst multiple users, care must be taken with user specific data. For example, this means that sensitive user information should not be stored in an instance variable as the instance is shared amongst many users. This can be overcome by using a HttpSession object that can be obtained from the initial request. Each session object is linked to a single user.

          How Servlets work

          Step 1: A user using a web browser requests some information from the web server via an http request.

          Step 2: The web server receives the request. If the request is for a straightforward HTML page then the appropriate HTML file will be loaded. If the request is to a servlet, then the web container will load and initiate the servlet (unless it was already running). This is done by running the servlet on a Java virtual machine (JVM).

          Step 3: The servlets’ init() method is then executed. This method is the equivalent of the init() method defined for applets. That is, it is executed only once, when the servlet is first created. It should be used in the same way as the init() method for applets. That is, as the servlets initialisation method (rather than defining a constructor). The init() method must complete before any requests are handled.

          Step 4: The servlet will receive the HTTP request and perform some ty pe of process. Each request is handled by its own thread (lightweight Java process). Depending upon the request one of the following methods will be called to handle the request:

          • doGet – handles GET, conditional GET and HEAD requests.
          • doPost – handles POST requests.
          • doPut – handles PUT requests.
          • doDelete – handles DELETE requests.

          Step 5: The servlet will return a response back to the Web server from one of the above methods.

          Step 6: The Web server will forward the response to the client.

          Step 7: When requested, the web server will terminate the servlet. This may be done by the web server administrator. At this time the destroy() method is called. This method runs only once and is used to “tidy” up any system resources used by the servlet etc. For the servlet to be run again, it must be reloaded by the web server.

          Wednesday, August 17, 2005

          A slightly bigger 'Hello World'

          The code is shown below is simplest that you can imagine and does very unusual thing!
          It is slightly bigger than "Hello World!" program but does much more. Can you make a guess what the program outputs?

          public class test{
          public static void main(String args[]){
          for (int i = 0;i < args.length; i++) {
          System.out.println("File " + i + ":" + args[i]);
          }
          if (args.length<=0) {
          System.out.println("No files!");
          }
          }
          }


          After compilation, if you run it like this:
          java test *
          it lists all files in the current directory on Windows or in any shell in UNIX.

          If you do: java test .*
          on UNIX it also shows all hidden files.

          You can ask how can we get this list without any file handling functionality in the code?
          Indeed looks mysterious...
          But in reality everything is very simple.
          When you type "*" (wildcard) OS (DOS, Windows, UNIX), not Java (!!!) sends the list of files in the current directory to your program as a list of parameters.
          And you see this list...

          Two-phase commits

          The two-phase commit protocol ensures that all the resource managers either commit a transaction or abort it. In the first phase, the JTS asks each resource manager if it is prepared to commit. If all the participants affirm, then in the second phase the JTS(Java Transaction Service) broadcasts a commit message to all of them. If any part of the transaction fails - for instance, if a resource manager fails to respond to the prepare request, or if a resource manager responds negatively, then the JTS notifies all of the resource managers that the transaction is aborted. This is the essence of the two-phase commit protocol.

          Tuesday, August 9, 2005

          Aryan


          Image025.jpg
          Originally uploaded by rgarg.
          This is Aryan, my son. He is 2 1/2 yrs old now, and have just started attending a playschool.

          No Need to Click Here - I'm just claiming my feed at Feedster

          [JSE 5.0] Performance Testing Example

          Bruce Eckel had an interesting post on performance testing the collection classes. Basically, he is comparing the different classes, running a myriad of insertion and delete tests and then timing the operation. He uses System.nanoTime() and to quote him, “typically nanoTime() produces values with a granularity that is greater than one (and this granularity will vary with machines and operating systems)”.

          A List of JDBC Drivers

          Continuing from What are the different type of JDBC drivers?, here is a listing of some of the popular JDBC Drivers available.
          I have so far used Oracle Thin driver, IDS Server, Hypersonic SQL, Sprinta Driver (for MS-SQL Server) and MM.MySQL Drivers beside JDBC ODBC Bridge, and I think your own list would also be somewhat similar. Or is it different?

          Yawn of theTiger

          A white tiger yawns as he lays in a pond at the New Delhi Zoological Park in New Delhi.

          I just adore the pic...

          Total Pageviews

          Diving into the Controversial World of IPL with Lalit Modi

          Lalit Modi, the mastermind behind the Indian Premier League (IPL), recently had a candid interview with Raj Shamani. The interview delved d...