Saturday, April 30, 2011

Conditional tags in blogger

  please read this before going down ----- how-to-put-widget-on-specific-page-of-your-blog

Conditional tags in blogger are used to tell browsers what to do in certain conditions. For example, when we use:

<b:if cond='data:blog.pageType == &quot;item&quot;'>
Hello world
<b:else/>
Goodbye Cruel World
</b:if>
It gives the browser the condition that when it’s an item (post) page then show “Hello world” otherwise, for every other pages show “Goodbye Cruel World”. Interesting, isn’t it.

A conditional tag comes handy when you are designing your Blogger blogs and customizing it from the scratch to take it to the next level. But first you need to know how many types of pages are there in Blogger and then how to use the conditional tags respective to that type of page. In this tutorial I will try to cover most of it, so let’s start.

Type of Pages in Blogger and Conditional Tags For It

1. Item Page
Item page refers to the individual post pages. It’s the page when you click the tile of the post or the read more link in blogger to read the full post. The conditional tag:
<b:if cond='data:blog.pageType == &quot;item&quot;'>
Hello World
</b:if>

Kinds of Computer Languages


  • Imperative
    • Specifies how a computation is to be done.
    • Examples: C, C++, C#, Fortran, Java
  • Declarative
    • Specifies what computation is to be done.
    • Examples: Haskell, ML, Prolog
  • von Neumann
    • One whose computational model is based on the von Neumann architecture.
    • Basic means of computation is through the modification of variables (computing via side effects).
    • Statements influence subsequent computations by changing the value of memory.
    • Examples: C, C++, C#, Fortran, Java
  • Object-oriented
    • Program consists of interacting objects.
    • Each object has its own internal state and executable functions (methods) to manage that state.
    • Object-oriented programming is based on encapsulation, modularity, polymorphism, and inheritance.
    • Examples: C++, C#, Java, OCaml, Simula 67, Smalltalk



    • Scripting
      • An interpreted language with high-level operators for "gluing together" computations.
      • Examples: AWK, Perl, PHP, Python, Ruby
    • Functional
      • One whose computational model is based on the recursive definition of functions (lambda calculus).
      • Examples: Haskell, Lisp, ML.
    • Parallel
      • One that allows a computation to run concurrently on multiple processors.
      • Examples
        • Libraries: POSIX threads, MPI
        • Languages: Ada, Cilk, OpenCL, Chapel, X10
        • Architecture: CUDA (parallel programming architecture for GPUs)
    • Domain specific
      • Many areas have special-purpose languages to facilitate the creation of applications.
      • Examples
        • YACC for creating parsers
        • LEX for creating lexical analyzers
        • MATLAB for numerical computations
        • SQL for database applications
    • Markup
      • Not programming languages in the sense of being Turing complete, but widely used for document preparation.
      • Examples: HTML, XHTML, XML

    Transformers 3 Dark of the Moon Teaser Trailer - Official (HD)










    Harry Potter and the Deathly Hallows Part 2




    Description: The end begins as Harry, Ron, and Hermione go back to Hogwarts to find and destroy Voldemort's final horcruxes, but when Voldemort finds out about their mission, the biggest battle begins and life as they know it will never be the same again.
    Related Titles: Harry Potter and the Deathly Hallows: Part 2
    Related Names:Michael Gambon, Jim Broadbent, Michelle Fairley, Alan Rickman, Miranda Richardson, Emma Thompson, Jamie Campbell Bower, Julie Walters, Tom Felton, Bonnie Wright, Natalia Tena, Ralph Fiennes, Domhnall Gleeson, Ciarán Hinds, Evanna Lynch, J.K. Rowling, Simon McBurney, Peter Mullan, Gary Oldman, David Yates, Steve Kloves, Jason Isaacs, James Phelps, Nick Moran, Robbie Coltrane, Toby Regbo, Helen McCrory, Clémence Poésy, Timothy Spall, David Thewlis, Warwick Davis, Rupert Grint, Emma Watson, Dave Legeno, Maggie Smith, John Hurt, Oliver Phelps, David Bradley, Kelly Macdonald, Helena Bonham Carter, Daniel Radcliffe

    TeamViewer

    TeamViewer (full version)

    Friday, April 29, 2011

    Top Search terms

    iphone 4 - The future is in the details

    The future is in the details

    When creating iPhone 4, Apple designers and engineers didn’t start with a clean sheet of paper. They started with three years of experience designing and building the phones that redefined what a phone can do. iPhone 4 is the result of everything they’ve learned so far. And it’s all contained in a beautiful enclosure a mere 9.3 millimeters thin, making iPhone 4 the world’s thinnest smartphone.

    firefox - 4 Browsing Made Easy

    Browsing Made Easy

    DOWNLOAD FIREFOX -4 

    Awesome Bar

    Awesome Bar screenshot

    fera-vs-fema

    Thursday, April 28, 2011

    JSP : Database Connectivity



    Why have a chapter about database connectivity in a book on Servlets and
    JSP? Databases are widely used in business today. Just about every real-world
    application will use databases in some form or another. The advertised mindset
    in J2EE is to build an application that uses an EJB layer to hide database con-
    nectivity. In practice this can work, but it is often more problematic than it is
    helpful. In this book we are taking the approach that you should not have to use
    EJB and that instead you should know more about database connectivity. By
    taking this approach, you will be able to build complete Web Applications
    without having to worry about a slew of other J2EE specifications. However, if
    one day you decide those other specifications are needed, you will be more than
    prepared for them. In this chapter we will briefly introduce databases and SQL,
    but the focus will be on JDBC and successfully using Java to manipulate a
    database. You will be expected to pick up a good book on SQL if you want to be
    a database guru.
    This session we discusses the following topics:
    • What a database, relational database, and SQL are.
    • CRUD (Creating, Reading, Updating, and Deleting database tables).
    • JDBC (Java Database Connectivity).
    • javax.sql.DataSource: an abstract method for obtaining a reference
    to a database.
    • java.sql.Connection: Java representation of a database connection.
    • java.sql.Statement: Executing queries against a database.
    • java.sql.ResultSet: Obtaining results of a database query
    • Optimally using JDBC.
    • JDBC Web Application design patterns.






























































    jsp:forward

    <jsp:forward/>
    JSP provide an equivalent to the RequestDispather.forward() method by use of
    the forward action. The forward action forwards a request to a new resource and
    clears any content that might have previously been sent to the output buffer by
    the current JSP. Should the current JSP not be buffered, or the contents of the
    buffer already be sent to a client, an IllegalStateException is thrown.

    jsp:include


    <%@ include %> and <jsp:include />

    The include directive is used to include text and/or code at translation time of a
    JSP. The include directive always follows the same syntax, <%@ include
    file="relativeURL" %>, where the value of relativeURL is replaced with the file
    to be inserted. Files included must be part of a Web Application. Since include
    directives take place at translation time, they are the equivalent of directly
    including the source code in the JSP before compilation and do not result in per-
    formance loss at runtime.
    Server-side includes are a commonly used feature of JSP. Includes allow the
    same repetitious bit of code to be broken out of multiple pages and have one
    instance of it included with them all. A good example to use is including a
    common header and footer with multiple pages of content. Usually this tech-
    nique is used to keep a site’s navigation and copyright information correct and
    maintainable for all individual pages on the site.As an example take the following
    two files, header.jsp and footer.jsp.
    The header.jsp file (fig 1) includes information that is to appear at the
    top of a page. It includes site navigation and other miscellaneous information.
    This header also tracks how many people have visited the site since the last time
    the Web Application was reloaded by reusing code from PageCounter.jsp.
    fig 1 header.jsp
    <%! int pageCount = 0;
    void addCount() {
    pageCount++;
    }
    %>
    <% addCount(); %>
    <html>
    <head>
    <title>Header/Footer Example</title>
    </head>
    <body>
    <center>
    <h2>Servlets and JSP the J2EE Web Tier</h2>
    <a href="http://www.jspbook.com">Book Support Site</a> - 
    <a href="ShowSource">Sites Source code</a><br>
    This site has been visited <%= pageCount %> times.
    </center>
    <br><br>


    The footer.jsp file (fig 2) includes information that is to appear at
    the very bottom of a page. It includes copyright information, disclaimers, and
    any other miscellaneous information.
    fig 2 footer.jsp
    <br><br>
    <center>Copyright &copy; 2003
    </center>
    </body>
    </html>
    By themselves header.jsp and footer.jsp do not do much, but when com-
    bined with some content, a full page can be generated. For this example the
    content does not matter. Arbitrarily make up a JSP, but be sure to include
    header.jsp at the top of the page and footer.jsp at the bottom. fig 3 pro-
    vides an example of such a page.
    fig 3 content.jsp
    <%@ include file="header.jsp" %>
    Only the content of a page is unique. The same header and footer 
    are reused from header.jsp and footer.jsp by means of the include 
    directive
    <%@ include file="footer.jsp" %>


    Save all three files, header.jsp, footer.jsp, and  content.jsp, in the base
    directory of the jspbook Web Application and browse to http://127.
    0.0.1/jspbook/content.jsp. All three files are mashed together at translation
    time to produce a Servlet that includes the contents of header.jsp, content.jsp,
    and footer.jsp in the appropriate order. Figure shows a browser rendering
    of the output.




    So what is the advantage of this approach over combining header.jsp,
    content.jsp, and footer.jsp all in one file in the first place? As the files are set
    up now, many more content pages can be created that reuse the header and
    footer. The header and footer can also be changed at any given time, and the
    changes are easily reflected across all of the JSP

    few more JSP SYNTAX AND SEMANTICS


    Directives
    Directives are messages to a JSP container. They do not send output to a client,
    but are used to define page attributes, which custom tag libraries use and which
    other pages include. All directives use the following syntax.
    <%@ directive {attribute="value"}* %>
    Directives may optionally have extra whitespace after the <%@ and before the
    %>. There are three different JSP directives for use on a page page, taglib, and
    include.

    Wednesday, April 27, 2011

    JSP: Declarations

    Declarations are the third and final scripting element available for use in JSP. A
    declaration is used like a scriptlet to embed code in a JSP, but code embedded by
    a declaration appears outside of the _jspService()method. For this reason code
    embedded in a declaration can be used to declare new methods and global class
    variables, but caution should be taken because code in a declaration is not
    thread-safe, unless made so by the writer of that code.

    JSP:Expressions

    Expressions provide an easy method of sending out dynamic strings to a client.
    An expression must have a start, <%=, end, %>, and an expression between. An
    expression element differs in syntax from a scriptlet by an equal sign that must
    appear immediately after the start. Expressions always send a string of text to a
    client, but the object produced as a result of an expression does not have to
    always end up as an instance of a String object.Any object left as the result of an
    expression automatically has its toString() method called to determine the
    value of the expression. If the result of the expression is a primitive, the prim-
    itive’s value represented as a string is used.

    JSP: scriptlets

    Scriptlets
    Scriptlets provide a method for directly inserting bits of Java code between
    chunks of template text. A scriptlet is defined with a start ,<%, an end, %>, with
    code between. Using Java, the script is identical to normal Java code but without
    needing a class declaration or any methods. Scriptlets are great for providing low-
    level functionality such as iteration, loops, and conditional statements, but they
    also provide a method for embedding complex chunks of code within a JSP.
    For many reasons complex scriptlets should be avoided. This is mainly due to
    the fact that the more scriptlets are used the harder it is to understand and
    maintain a JSP. In this chapter most of the scriptlet examples are purposely kept
    simple. This aids in directly demonstrating the core functionality of JSP, but it is
    also done so that examples do not appear to encourage heavy use of scriptlets. As
    an introduction, Listing 2 provides a simple JSP that loops to produce multiple
    lines of text. Looping is accomplished the same as in Java but by placing the
    equivalent Java code inside scriptlet elements. Loop.jsp
    Listing 2 
    <html>
    <head>
    <title>Loop Example</title>
    </head>
    <body>
    <% for (int i=0; i<5;i++) { %>
    Repeated 5 Times.<br>
    <% } %>
    </body>
    </html>
    Save  Loop.jsp in the base directory of the jspbook Web Application and
    browse to http://127.0.0.1/jspbook/Loop.jsp. The page shows up with the
    statement, “Repeated 5 Times.”, repeated five times.

    output
    Repeated 5 Times
    Repeated 5 Times
    Repeated 5 Times
    Repeated 5 Times
    Repeated 5 Times


    It is important to note that the contents of the scriptlet did not get sent to a
    client. Only the results of the scriptlet did. This is important because it shows that
    scriptlets are interpreted by a container and that code inside a scriptlet is not by
    default shared with visitors of the JSP.
    A JSP may contain as many scriptlets as are needed, but caution should be
    taken not to overuse scriptlets. Scriptlets make a JSP very hard to maintain and
    are not easily documented; for example, tools like javadoc do not work with JSP

    JSP Syntax and Semantics


    JSP is not governed by the syntax and semantics defined by the Java 2 specifica-
    tions. Translated JSP source code is just Java,but when you author a JSP, you abide
    instead by the rules laid out in the JSP specification. With each release of the JSP
    specification, these rules grow, and they cannot be easily summed by a few sen-
    tences. The majority of this chapter focuses on explaining the current syntax and
    semantics of JSP. Much of the functionality found in JSP is taken directly from the
    underlying Servlet API .
    Everything in a JSP is broken down into two generic categories called elements
    and template data. Elements are dynamic portions of a JSP. Template data are the
    static bits of text between. Template data are easily categorized as they are all the
    text arbitrarily placed on a JSP and meant to be directly sent to a client. Elements
    are easily categorized as custom actions, tags, and the content allowed to be in
    between as defined by the JSP specifications.
    The concept of elements and template data is important to understand as it
    dictates when, where, and what text will do when placed in a JSP. This chapter has
    yet to introduce any elements, but it has shown a use of template text. The
    HelloWorld.jsp example was entirely template text. The corresponding Servlet
    generated from HelloWorld.jsp treated this text as static content and sent it as
    the content of a response. While HelloWorld.jsp only had one big chunk of tem-
    plate text, more complex JSP follow the same rule. Any chunk of template text is
    taken and sent directly to a client as it appears on the JSP. Elements on the other
    hand are not sent directly to a client. An element is interpreted by a JSP container
    and defines special actions that should be taken when generating a response.
    Template text does not change, and this little section defines it in total.
    Elements are what make JSP dynamic, and elements are further explained
    throughout the rest of the chapter. Elements can be broken down into three dif-
    ferent categories: scripting elements, directives, and actions. The following self-
    named sections explain these elements.
    Two Types of Syntax
    JSP containers are required to support two different formats of JSP syntax:
    normal and XML-compatible. The normal JSP syntax is a syntax designed to be
    easy to author. The XML-compatible JSP syntax takes the normal JSP syntax and
    modifies it to be XML-compliant
    1
    . Both syntaxes provide the same functionality,
    but the XML-compatible syntax is intended to be more easily used by devel-
    opment tools. In the examples of this book the normal JSP syntax is preferred as
    it is easily read, understood, and will be familiar if you have used older versions
    of JSP.
    Just because the XML syntax will not be appearing much in this book’s
    examples does not mean it is the lesser of the two syntaxes. The JSP XML syntax
    introduced in the JSP 1.2 specification, from a developer’s perspective, is cer-
    tainly a hassle to use compared to the regular syntax. This is largely due to the
    complexity and strict enforcement of syntax the JSP 1.2 XML syntax had. JSP 2.0
    remedies the problem by providing a much more flexible XML syntax. Later on
    in the chapter this new, more flexible XML syntax is further explained.
    Scripting Elements
    The simplest method of making a JSP dynamic is by directly embedding bits of
    Java code between blocks of template text by use of scripting elements. In theory
    JSP does not limit scripting elements to only those containing Java code, but the
    specification only talks about Java as the scripting language, and every container
    by default has to support Java. Examples in this book use Java as a scripting lan-
    guage. There are three different types of scripting elements available for use in
    JSP: scriptlets, expressions, and declarations.

    Tuesday, April 26, 2011

    Difference Between Servlets and JSP




    A clear and important distinction to make about JSP is that coding one is nothing
    like coding a Servlet. From what this chapter has explained, it might appear that
    JSP is just a simple version of Servlets. In many respects JSP is in fact a simple
    method of creating a text-producing Servlet; however, do not be fooled into
    thinking this mindset is always true.As the chapter progresses, it will be clear that
    JSP and Servlets are two very distinct technologies. Later, after custom tags are
    introduced, the degree of separation between the two will seem even larger. The
    use of JSP for easily making a Servlet really only applies in the simplest of cases.
    To show how vastly different the code for a JSP can be from a Servlet, Listing
    displays the code for the JSP equivalent of the HelloWorld Servlet

    HelloWorld.jsp
    <html>
    <head>
    <title>Hello World!</title>
    </head>
    <body>
    <h1>Hello World!</h1>
    </body>
    </html>

    They are quite different! You’ll recall the code for HelloWorld.java and
    notice the two look nothing alike. The code for the JSP is actually identical to the
    text generated by the HelloWorld Servlet, not the source code. Authoring an
    HTML-generating JSP is as easy as just authoring the HTML. Compared to using
    print() and println()methods in Servlets,the JSP approach is obviously easier.
    This is why simple JSP are usually considered a quick method of creating text-
    producing Servlets.
    Deploying a JSP is also simpler; a Web Application automatically deploys any
    JSP to a URL extension that matches the name of the JSP. Test out HelloWorld.jsp
    by saving it in the base directory of the jspbook Web Application then browsing to
    http://127.0.0.1/jspbook/HelloWorld.jsp

    From looking at the results of the example, it certainly does appear Hello
    World.jsp is a simple form of HelloWorld.java. What is not shown, but is very
    important to understand, is that HelloWorld.jsp is also actually compiled into
    equivalent Servlet code. This is done in what is called the translation phase of JSP
    deployment and is done automatically by a container. JSP translation both is and
    is not something of critical importance for a JSP developer to be aware of. JSP
    translation to Servlet source code is important because it explains exactly how a
    JSP becomes Java code. While it varies slightly from container to container, all
    containers must implement the same JSP life cycle events. Understanding these
    life cycle methods helps a JSP developer keep code efficient and thread-safe.
    However, JSP translation is not of critical importance because it is always done
    automatically by a container. Understanding what a container will do during the
    translation phase is good enough to code JSP. Keeping track of the generated
    Servlet source code is not a task a JSP developer ever has to do.
    JSP translated to Servlet code can be found by looking in the right place for
    a particular container. Tomcat stores this code in the /work directory of the
    Tomcat installation. Generated code is never pretty, nor does it always have the
    same name. Listing 3-2 was taken from HelloWorld$jsp.java in the /work/
    localhost/jspbook directory. It is the Servlet code generated for HelloWorld.
    jsp that Tomcat automatically compiled and deployed

    Tomcat-Generated Servlet Code for HelloWorld.jsp
    package org.apache.jsp;
    import javax.servlet.*;
    import javax.servlet.http.*;

    import javax.servlet.jsp.*;
    import org.apache.jasper.runtime.*;
    public class HelloWorld$jsp extends HttpJspBase {
    static {
    }
    public HelloWorld$jsp( ) {
    }
    private static boolean _jspx_inited = false;
    public final void _jspx_init() throws
    org.apache.jasper.runtime.JspException {
    }
    public void _jspService(HttpServletRequest request,
    HttpServletResponse  response)
    throws java.io.IOException, ServletException {
    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    String  _value = null;
    try {
    if (_jspx_inited == false) {
    synchronized (this) {
    if (_jspx_inited == false) {
    _jspx_init();
    _jspx_inited = true;
    }
    }
    }
    _jspxFactory = JspFactory.getDefaultFactory();
    response.setContentType("text/html;charset=ISO-
    8859-1");
    pageContext = _jspxFactory.getPageContext(this, request,
    response,
    "", true, 8192, true);
    application = pageContext.getServletContext();
    config = pageContext.getServletConfig();
    session = pageContext.getSession();
    out = pageContext.getOut();
    // HTML // begin
    [file="/HelloWorld.jsp";from=(0,0);to=(8,0)]
    out.write("<html>\r\n<head>\r\n<title>Hello
    World!</title>\r\n</head>\r\n<body>\r\n<h1>Hello
    World!</h1>\r\n</body>\r\n</html>\r\n");
    // end
    } catch (Throwable t) {
    if (out != null && out.getBufferSize() != 0)
    out.clearBuffer();
    if (pageContext != null)
    pageContext.handlePageException(t);
    } finally {
    if (_jspxFactory != null)
    _jspxFactory.releasePageContext(pageContext);
    }
    }
    }



    Do not bother trying to read through and understand the generated code.
    The important point to understand is that a container handles a JSP as a Servlet
    but does so behind the scenes
    . This ties directly back to the greater point that JSP
    are really just Servlets. The difference between the two technologies is not in the
    life cycles or how a container manages them at runtime. The difference between
    Servlets and JSP is the syntax they offer for creating the same functionality. With
    JSP it is almost always simpler to create text-producing Servlets, but normal
    Servlets are still best suited for sending raw bytes to a client or when complete
    control is needed over Java source code.


    JSP Basics

    JavaServer Pages (JSP) and Servlets are complementary technologies for producing dynamic Web pages via Java. While Servlets are the foundation for serverside Java, they are not always the most efficient solution with respect to development time. Coding, deploying, and debugging a Servlet can be a tedious
    task. Fixing a simple grammar or markup mistake requires wading through print() and  println() calls, recompiling the Servlet, and reloading a Web Application.Making a grammar or markup mistake is not hard, and the problem is compounded in complex Servlets. JSP complements Servlets by helping solve this problem and simplifying Servlet development.

    JSP Life Cycle
    Much like Servlets, understanding JSP requires understanding the simple life cycle that JSP follows. JSP follows a three-phase life cycle: initialization, service,and destruction, as shown in Figure This life cycle should seem familiar and is identical to the one described for Servlets .While a JSP does follow the Servlet  life cycle, the methods have different names. Initialization corresponds to the jspInit() method, service corresponds to the _jspService() method, and destruction corresponds to the jspDestroy() method. The three phases are all used the same as a Servlet and allow a JSP to
    load resources, provide service to multiple client requests, and destroy loaded resources when the JSP is taken out of service.
    JSP is designed specifically to simplify the task of creating text producing HttpServletobjects and does so by eliminating all the redundant parts of coding a Servlet. Unlike with Servlets there is no distinction between a normal JSP and one meant for use with HTTP. All JSP are designed to be used with HTTP and to generate dynamic content for the World Wide Web. The single JSP _jspService() method is also responsible for generating responses to all seven
    of the HTTP methods. For most practical purposes a JSP developer does not need to know anything about HTTP, nor anything more than basic Java to code a dynamic JSP.