Thursday, June 24, 2010

Google AppEngine – Hello World Example


The best thing about Google AppEngine is you can run your java web-application in Google infrastructure for FREE of cost (up to certain user hits).I was really excited to know this, because it's really a great opportunity to deliver lots of small web utility at free of cost.
Let's get started:



Installing Eclipse AppEngine plugin:

              Google provided Eclipse plugin for developing & deploying AppEngine application easily. Based on the Eclipse version we need to select different update site URL, in our example I am using Eclipse 3.5 (Galileo) so i am using update site URL  as http://dl.google.com/eclipse/plugin/3.5


Steps 01:

In Eclipse, select Help menu and click "Install new Software" option as below.

Step 02:

Once the Wizard opens, click Add button. Below pop-up box should be displayed where you have to enter the update URL (based on the Eclipse version) and a unique name. Then click ok.

Step 03:

Below windows screen should be displayed, where SDK and plugin files are displayed. Check both check boxs and click Next.

Now Eclipse connect to the server and downloads the files, once the files are downloaded it displays license agreement page, once you have agreed to that, it starts installing the files and request you to restart the eclipse .After restarting  the eclipse, you should see below new icons in your eclipse top left corner.

Creating Application:

Click on google icon, which will open below application creation wizard.




 

Project Name:  Name of the project.

Package Name: you have to specify the default package name, based on this your files are created under the given packages.

Apart from that, it also supports GWT supports, currently we can ignore the GWT support option and we should select only AppEngine Support.Click Finish.


Default Project:

Once you click finish, plugin will create a default project skeleton, where you will have directory structure which is required by google appengine."war" is the deployment folder, where all your dynamic files and static files should be placed.

Debugging the Application:

Right click the project, select "dubug as" and select Web Application option.Now the code should compiles and then eclipse starts the server. You can view the application using URL http://localhost:8888/<application-name>



Deploy Application:

Once you done with the debugging, it's time to deploy the application. Select icon and eclipse pops-up below dialog box.


Click "App Engine project Settings" option, which open the windows where the application ID should be entered. If you are creating first time then click "My application" option which pop-up the browser and lands in creation of application Id.



Click "OK", now you will be back to the previous screen, now enter your password. Once you enter the password the Google AppEngine will connect to the server and the files are deployed.

Once the Eclipse finishes the deployment, now you can access the Hello world example in the below URL <Application_ID>.appspot.com/<project_name> example: http://its-passion4java.appspot.com/passion4java
 

That's it, now the hello world application is live in Google infrastructure.Please post your comments, if you think some thing can be added ;)...

Saturday, December 19, 2009

Things to be remembered before including a file in your JSP page.

Their are 3 ways in J2ee [as for as i know ;)] from which you can include a file inisde your JSP. Let see what is the pros cons of each one.

<@inlcude file="someJunkIncludeFile.jsp">
  • As include is a page directive, you CANNOT pass dynamic values (by using scriplets or EL expressions)
  • It copies all the text which are in the included file (say someJunkIncludeFile.jsp) to the parent page.This happens every time when your parent page is getting recompiled, so make sure that if you have more include in a parent page, and the parent page will be recompiled often, then this may lead you a performance overhead :(
  • In advance containers like Tomcat 6, the container will automatically recompile your parent jsp, if any of your child pages or included pages are updated
  • In XML-based Jsp tags, you can specify the <@include/> as
<jsp:include page="someJunkIncludeFile.jsp"/>

  • JSP Action include can allow the dynamic values (by using scriplets or EL expressions) as a argument.(Thats why they call it as jsp Action include)
  • You can pass dynamic argument values to the include JSP page using param attribute.Below is the example which will pass values to the child page.



  • 
        
    
    



  • In your child page you can use the value test in the request scope by accessing.


  • < % =request.getParameter("test") % >

  • You can't pass any input arguments in query string to the child page, when you are including from the parent page

  • 
    

  • In above code test parameter can't be accessed from the child page, as they passed as a input query.
JSTL < c:import url="someJunkIncludeFile.jsp"/ >
  • c:import is 99.99% similar to jsp:include, the only difference i can feel is it can access the resources which are outside your application
  • in the url attribute (name sugest) we need to specify the entire URL of the resource. as below

Wednesday, December 16, 2009

Why Tomcat Container should do this.

I was trying an example with @include and , in Tomcat 6. As we know if you use @include all the content in the child page (my_include.jsp), will be copied to your parent page during translation time, and any changes happens to the child will be reflected only when the parent page get recompiled (due to any changes happens in parent page). I was expecting the same and trying a simple example as below. 

File: parent.jsp
 < html >
 < body>
  I am in parent< %@include file="child.jsp" %>< /br>
   < /body>
 < /html >
File: child.jsp
 I am in Included page...

So when we hit parent.jsp, all the content which is in child.jsp should be copied to page.jsp and it will be compiled. After compiling parent.jsp, if any changes happen in child.jsp will not be displayed until when the parent.jsp is getting recompiled.

When I tried the same, but I was getting a different output, after compiling my parent.jsp and if I make any changes to my child.jsp Tomcat 6 recompiles my parent.jsp again and I was getting the updated changes in child.jsp in the output.

I was searching this topic and found that some of the advance container is friendly and they check if any @included pages are getting updated when a request comes to main (parent.jsp) file. If that so then they recompiling the parent page again. Finally it really important that this scenario was NOT GUARANTEED BY THE SPEC!

Why they do?

* If they containers are doing this (container may thing they are friendly with us), then what’s the difference between @include and in terms of getting the updated content from the child. 
* Doing this may not bring down the performance of the parent page, if the parent page has lots of included file. So any changes in any of the included file, the parent jsp should compile again by coping all the content from all the included jsp files.
* And finally this function is not portable, because this was NOT GUARANTEED BY THE SPEC! 

Any thoughts? Thank You
 

This content comes from a hidden element on this page.

The inline option preserves bound JavaScript events and changes, and it puts the content back where it came from when it is closed.
Click me, it will be preserved!

If you try to open a new ColorBox while it is already open, it will update itself with the new content.

Updating Content Example:
Click here to load new content