Tuesday, March 20, 2007

BarCamp Bangalore 3 - Social Tech


Guys BarCamp, Bangalore (BCB3) is back again..

The Theme - The impact of technology on society and our lives, and vice versa.

At this BarCamp we would like you guys to talk over ups and downs of technology and how technology is affecting our day to day life or rather society as whole..
A wide range of topics under one roof: e-goverence, copyright law, electronic media and many other new innovations to name a few..
So come up with your own topics, ideas and issues and help your fellow campers to gain most out of this camp.

When and Where -
Saturday-Sunday, March 31 & April 1, 2007; 8:30 AM to 6:30 PM, at the Indian Institute of Management, Bangalore (IIMB).

Register -
Registrations for BarCamp Bangalore 3 are open. We already have 200+ registrations prior to any publicity for the event. Barcamp Bangalore typically attracts participants from around India and overseas. You can register for the event here.

Sponsors -
Interested in sponsoring the event? We love you! Step this way please
So see you campers there ...

20 must-have Firefox extensions

As we know Firefox is a great software package for browsing the net, but what makes this open-source browser so special is the ability to customize it via extensions and themes to really make it yours. The problem is, there are so many available add-ins, it's tough to know what's worth installing and what's just going to junk up your system.

Below is the list prepared by Mr. Peter Smith (Computerworld) of 20 best extensions and add-ins used and recommended by hardcore Web surfers, developers and IT pros. Whether you're looking for more streamlined surfing, improved look and feel, cool design tools or serious Web development help, there's something here for you and be sure to share your favorite extension in the comments at the bottom of the page.

Category 1>> Tools for taming the Web

StumbleUpon
First, a warning. StumbleUpon is hazardous to your productivity! StumbleUpon is one of these social networking Web applications that are becoming so popular lately. This one provides a way to find new Web sites that you may find enjoyable or useful.

This extension adds a StumbleUpon tool bar to Firefox. You can get to all the core functionality of StumbleUpon via this tool bar, including setting up an account. You pick some initial categories of the kinds of sites you're interested in (a few examples: Ancient History, Humor, Self-improvement) as part of the sign-up process, and can always tweak these later.

The StumbleUpon tool bar.


The StumbleUpon tool bar. (Click image to see larger view)

Once everything is set up, you click the Stumble! button in the tool bar to be taken to a random site that has something to do with your categories. If you don't like the site, click the Thumbs Down button. If you do like it, click Thumbs Up. The more sites you rate, the better your Stumbles will match your tastes. If you rate a site that isn't in the StumbleUpon database yet, you can enter some basic information about it so others can stumble onto it.

StumbleUpon isn't all that practical, but it is fun and can transport you back to the days when just idly surfing the Net turned up all kinds of interesting things.

Version reviewed: 2.91
addons.mozilla.org/firefox/138

Gmail Manager & Yahoo Mail Notifier
These two extensions do basically the same thing, each for its respective Web mail service.

The Yahoo Mail Notifier is fairly basic; it just puts a small mail icon in your status bar and indicates how many new messages are in your Yahoo mail account. It'll display a little pop-up to catch your attention if you want it to. Clicking the icon takes you to Yahoo mail.

Version reviewed: 0.9.9.2
addons.mozilla.org/firefox/1264


The Gmail Manager pop-up display.


The Gmail Manager pop-up display. (Click image to see larger view)

The Gmail Manager does all this and more. If you hover your mouse over it, you'll see the total number of new messages, how many spam messages you have, new message counts for all your labels and how much space your mail is taking up. Below all that is a listing of your most recent 10 messages, showing From, Subject and first line of the body of the mail (you can turn all this off). It also supports multiple Gmail accounts, and you can set it to cause all mailto: links to open up a Compose New Message window in Gmail.

Version reviewed: 0.5.3
addons.mozilla.org/firefox/1320

Sorry, Hotmail users. I wasn't able to find a notifier for you.

Greasemonkey
Let's get this out of the way right up front: Greasemonkey is not for the faint of heart. It basically allows you to add JavaScript to any Web page, but writing these scripts requires a good knowledge of scripting. The good news is that there are many generous souls out there who share the scripts they create.

When first installed, Greasemonkey does nothing. It just enables the scripting. You'll have to write, or install, scripts before you see any changes on your pages.

So what do these scripts do? Almost anything you can do with JavaScript. For example, I use both Google's Gmail and Reader services. I found a script that causes Reader to appear on the same page as my Gmail. That's a pretty big change. (It's easy to disable a script, and even easier to universally disable Greasemonkey, in case you need to undo a change.)

Want your Google search results to appear in two columns? There's a Greasemonkey script for that.


Want your Google search results to appear in two columns? There's a Greasemonkey script for that.

Then there are lots of scripts that do small things like remove the Edit features from Wikipedia. Most of us are never going to edit these pages, so why not clean them up a bit? Another script, shown here, makes Google search results appear in two columns to provide better use of space on wide monitors. The possibilities are endless.

Check out userscripts.org for a script repository. If you want to write your own scripts, try diveintogreasemonkey.org or pick up Mark Pilgrim's Greasemonkey Hacks from O'Reilly Media.

Version reviewed: 0.6.7.20070131.0
addons.mozilla.org/firefox/748



Category 2 >> Visual improvements

Firefox Showcase
Firefox Showcase is a great extension both because of its usability and because it takes away one feature advantage that Internet Explorer 7 has over Firefox: the ability to display thumbnails of all open windows and tabs.

Once you install the extension, you'll have a new Showcase submenu under the View menu. From here you can choose to show thumbnails of all tabs in the current window or all tabs in all windows. (IE7, incidentally, only shows thumbnails of the tabs in a particular window.)

Additionally, you can choose to show these thumbnails in a new tab or in a floating window.

Firefox Showcase doing its thing.


Firefox Showcase doing its thing. (Click image to see larger view)

You also get new options under the Sidebar submenu: a choice to open tabs from the current window, or from all windows, in Firefox's sidebar. No matter how you choose to display the thumbnails, once you do, clicking on one of them takes you to that window/tab combination.

In some ways, this extension is too complex for its own good. You can safely ignore most of the options and just use the extension in its default configuration.

If you habitually find yourself awash in open tabs, clicking around looking for the page you need, Firefox Showcase will save you a lot of aggravation.

Version reviewed: 0.9.2.1
addons.mozilla.org/firefox/1810

Cooliris Previews
This interesting extension allows you to preview a Web page before clicking off the one you're on. After installing Cooliris Previews, a small blue icon will appear next to any link you hover your mouse over. Slide the mouse over to that icon and a window pops up containing the destination page. For all intents and purposes, you're on that page, except if you move the mouse off the icon and the pop-up window, the preview vanishes.

At the top of the pop-up window are some additional icons that let you lock the window open, open the preview into a new tab, e-mail it to a friend (though this requires registration at the Cooliris Web site), close the window or use a Back button. (You can surf around in the preview window, ergo the Back button.)

A Cooliris preview of a YouTube video.


A Cooliris preview of a YouTube video. (Click image to see larger view)

It is in some ways more neat than useful, but for certain sites, such as YouTube, the preview is enhanced. If you preview a link to a YouTube page, only the video opens in the preview window.

In addition to the Preview feature, Cooliris adds a context-sensitive search feature to the right-click menu. Highlight a word or phrase on a page, right-click, choose Cooliris Search and select either thefreedictionary.com, Google Images, Google Search or Wikipedia to search on the highlighted term. If you hover the mouse pointer over any of these four selections, the results will display in a preview window. If you click, they'll open in a new tab.

If you find the preview icon is getting intrusive, you can easily disable previews by clicking an icon in the status bar. You can also disable/enable previewing on a site-by-site basis.

Version reviewed: 2.1
addons.mozilla.org/firefox/2207

Colorful Tabs & ChromaTabs
Colorful Tabs is pretty basic. It colors each of your tabs using lovely pastel colors. After a long day of research, this becomes more than just something pretty and can make life easier on tired eyes.

Colorful Tabs is a sight for sore eyes. Tab colors are assigned randomly.


Colorful Tabs is a sight for sore eyes. Tab colors are assigned randomly.

The version reviewed requires Firefox 2.0 or later. Version 1.4 of Colorful Tabs will work with earlier versions of Firefox. See the link for more details.

Version Reviewed: 1.9
addons.mozilla.org/firefox/1368

ChromaTabs is in many ways similar to Colorful Tabs. The difference is that ChromaTabs determines a tab's color based on the hostname in the URL. For instance, any tab displaying a Computerworld page might always be a light green color. If you surf away to a different site, the tab's color will change.

ChromaTabs looks similar, but its tab colors are assigned based on domain name. In this example, all tabs showing a <i>Computerworld</i> page would appear light green.


ChromaTabs looks similar, but its tab colors are assigned based on domain name. In this example, all tabs showing a Computerworld page would appear light green.

Version reviewed: 1.0
addons.mozilla.org/firefox/3810

It's a personal preference, really. Colorful Tabs assigns tab color at random, and as long as a tab stays open, its color remains the same, no matter where you surf. With ChromaTabs, the colors shift (and some might not be very appealing), but after a while you can tell at a glance where a Computerworld page is loaded just by scanning for that light green color.

Category 3 >> Matters of convenience

Google Browser Sync & Foxmarks Bookmark Synchronizer
If you use Firefox on more than one computer, you might be frustrated keeping track of what bookmarks are where. Google Browser Sync to the rescue. Using your existing Google account, Google Browser Sync will sync not only bookmarks, but sessions, persistent cookies, passwords and history among instances of Firefox on different machines. (This is user configurable on a broad scale -- i.e., you can choose to sync cookies, or not to sync cookies, but you can't make the decision based on individual cookies.) In addition to your Google account name and password, you'll assign a PIN to add additional security to the transaction.

Some of Google Browser Sync's options.


Some of Google Browser Sync's options.
(Click image to see larger view)

Version reviewed: 1.3.20061031.0
www.google.com/tools/firefox/browsersync

One downside is that the initial sync can take quite a while, and for some folks, Google Browser Sync might be overkill. If all you want to do is sync bookmarks, try Foxmarks Bookmark Synchronizer. You'll have to set up an account with Foxmarks (the same is true of Google, but many of us already have Google accounts), but the initial sync seems much faster.

Foxmarks offers fewer synchronization options.


Foxmarks offers fewer synchronization options. (Click image to see larger view)

As a bonus, you can access your bookmarks by navigating to my.foxmarks.com. This could be handy if you're on a borrowed machine somewhere.

Version reviewed: 0.84
addons.mozilla.org/firefox/2410

Session Manager
Session Manager is a handy utility to help you manage your Firefox tabs. If you're a Web surfer who habitually visits the same sites every morning, all you need do is open the sites in separate tabs and/or windows, and then use Session Manager to save the session under a name of your choosing. After that, every morning start up Firefox and go to Tools > Session Manager, pick your session and voila, all the windows and tabs open up just as you saved them.

You can also choose a saved session as your "Start Session" (instead of just using a start page) that'll open each time you launch Firefox. As an added bonus, Session Manager tracks your sessions as you surf, and if Firefox (or your system) crashes, you can recover the selection of tabs you had open when it crashed.

Session Manager makes it easy to reopen closed tabs.


Session Manager makes it easy to reopen closed tabs.

One last perk: If you accidentally close a tab, you can easily reopen it from the Session Manager menu.

While Firefox 2.0 has incorporated many of Session Manager's functions, I find Session Manager performs its tasks more elegantly and reliably. And if you're still on Firefox 1.5, Session Manager remains your lone option for these features. Note that the most current version of Session Manager requires Firefox 2.0 or later. Earlier, Firefox 1.5-compatible versions can be found on the Web site.

Version reviewed: 0.5.3.1
addons.mozilla.org/firefox/2324

All-in-One Gestures
This is one of those extensions that does more than you'll probably ever need, but the core function is to assign commands to "Gestures" made with the mouse. For instance, holding down the right mouse button and dragging the mouse a bit to the left issues a "Back" command. A right-mouse button/dragging up combo opens a new tab. And so on.


A few of the many gestures you can assign commands to.


A few of the many gestures you can assign commands to. (Click image to see larger view)

There are more than 90 commands available, and the gesture to trigger each is user-configurable. Will you ever remember 90 different gestures? Of course not. But find the commands you use often and assign each a gesture; you'll save yourself miles of mousing.

The extension also provides auto-scrolling, as seen in Internet Explorer. This is where you click the middle button, then move the mouse up or down to start the page continuously scrolling. The farther you move the mouse, the faster the page scrolls.

All-in-One offers a wide selection of small navigation improvements like these. It's really one of those "you have to try it to appreciate it" extensions. But the core functionality of accomplishing frequent tasks via a small twitch of the mouse makes this a must-have for its many advocates.

Version reviewed: 0.18.0
addons.mozilla.org/firefox/12

IE Tab
It's a fact of life that there are still Web sites out there that require (or work better with) Internet Explorer. IE Tab to the rescue. Once installed, it places a small icon in your status bar. Clicking this icon swaps out the rendering engine from Firefox's to Internet Explorer's. In my experience, this is particularly helpful with sites that refuse to play video in Firefox.

You can set filters so that certain sites are always displayed in an IE tab. In fact, the extension comes preconfigured with filters for the Microsoft Update site. It also adds an "Open Link in IE Tab" option to the right-click context menu of Firefox.

Since the extension uses IE's engine, this one is for Windows only.

Version reviewed: 1.3.1.20070126
addons.mozilla.org/firefox/1419

Download Statusbar
You're probably familiar with that sometimes-pesky Downloads window that pops up whenever you download a file in Firefox. Download Statusbar suppresses that window from popping up, and instead provides you the same information in the status bar at the bottom of the browser window. (You can still manually open the Downloads window if you find you need it.)

You can roll your mouse over the filename and get a pop-up tool tip with some extra information about your download, too (where it's being download from, and where it's being saved to, the speed of the download, percentage complete and so on).

Get download information in a status bar pop-up.


Get download information in a status bar pop-up.

An additional feature, still in beta, is to automatically run your virus scanner against downloaded files.

Pretty simple, but it helps to "clean up" the browsing experience. By the way, this is from the same developer as Download Sort, below.

Version reviewed: 0.9.4.5.1
addons.mozilla.org/firefox/26

Download Sort
If you find yourself doing a lot of "Save Link As" or "Save Image As" downloading, then Download Sort will be quite a timesaver. It allows you to file downloads by extension, or by a keyword or regular expression in the URL.

Here's how it works. After installing the extension, you set up filters. As an example, you might want any file with the extension .jpg to go into a Pictures folder and anything ending in .zip to go into an Archives folder on your drive.

Download Sort settings.


Download Sort settings. (Click image to see larger view)

Now when you right-click on a .jpg image and choose Save Image As, the image immediately downloads into your Pictures folder without any prompting. Right-click on a link to a .zip file and choose Save Link As, and again, the file goes right into your Archives folder. You can optionally have the extension create subdirectories according to date, domain and a few other criteria.

The big drawback here is that Download Sort doesn't intercept normal left-click downloads. It'd be great to see the developer add this capability.

Version reviewed: 2.5.7
addons.mozilla.org/firefox/25

Nuke Anything Enhanced
If you find yourself printing a lot of Web pages, this extension will help you save on ink. Once installed, it adds a "Remove this object" option to the right-click context menu. Place your mouse over information you don't need printed (menu bars, big graphical logos and so on) and use "Remove this object" to zap them temporarily. Clean up the page, then print just what you need.

A Mozilla Add-ons page, before and after removing the title with the Nuke Anything Enhanced extension.


A Mozilla Add-ons page, before and after removing the title image with the Nuke Anything Enhanced extension.

It can be a little fussy, since you don't know exactly what you're hovering over. Images are pretty straightforward, but menus and other page parts can take some trial and error. There's an "Undo Last Remove" option in case you accidentally zap something you need. Or you can just reload the page to restore it to its original state.

One limitation is that you can't easily nuke Flash content, since when you right-click on Flash, you get its context menu, not Firefox's. Sometimes you can find the container tag that holds the Flash, but it can take some trial and error.

Version reviewed: 0.54
addons.mozilla.org/firefox/951

Category 4 >> Information gatherers

Forecastfox
Forecastfox puts an up-to-date weather forecast in Firefox's status bar. Just click one of its icons to see the full weather report at AccuWeather.com.

A wide range of options gives you control over how much, or how little, information you want, including a radar image button, severe weather warnings and extended forecasts of up to eight days. You can set up profiles, each with its own set of options. Use these to get the weather in different zip codes if you're a traveler, or create profiles with lots of data for turbulent winter conditions and minimal data for warm, sunny summer days.

Forecastfox brings the weather to your status bar.


Forecastfox brings the weather to your status bar.

The only downside here is that, as with all extensions that rely on data from external Web sites, if the AccuWeather.com site isn't responding, you won't get any weather updates.

Version reviewed: 0.9.3.1
addons.mozilla.org/firefox/398


Helpful information from Answers.com.


Helpful information from Answers.com. (Click image to see larger view)

Answers
This one's simple: Just hold down the Alt key (Option key on a Mac) and click on a word, and a window will pop up with information about that word from Answers.com. (You can have the results displayed in a full window if you'd rather.) There's a More button in the pop-up that'll open a new tab with the full Answers.com results page.

For phrases, you still have to highlight, right-click and choose "Look up on Answers.com" to get results in a new tab.

Version reviewed: 2.2.22
addons.mozilla.org/firefox/735



Category 5 >> Web Developer Essentials

FireFTP
Why bounce between applications when you can use FireFTP and have a full-featured FTP client in one tab, and the page you're working on in another?

FireFTP adds an option to Firefox's Tools menu. Click on it and a new tab opens (you can set this to a new window if you prefer) with a traditional two-panel FTP client: local files on the left, remote on the right. By right-clicking on files you can tweak their permissions and all the other things you'd expect to be able to do via FTP.

FTP right from Firefox with FireFTP.


FTP right from Firefox with FireFTP. (Click image to see larger view)

One nice feature is "View on the Web," which opens the file on the remote server in a new tab. You can set up each host to "snip" out parts of the directory structure (/public_html, for example) so that you get valid URLs rather than the full "physical" path to the file.

The one disappointment is that the client is FTP only. When asked about SFTP support, the author responds (in a FAQ on his page), "Maybe in Version 2.0." Let's hope.

Warning: The combination of FireFTP and Firefox 2.0.0.1 exposes a regression bug in Firefox, causing high CPU usage. If you're still running 2.0.0.1, you should upgrade to 2.0.0.2 before installing FireFTP.

Version reviewed: 0.94.6
addons.mozilla.org/firefox/684

Firebug
Firebug is an essential tool for developers working on Web pages. It allows you to examine and tweak the HTML, CSS and JavaScript contained in a page, all on the fly. Firebug opens either as a panel at the bottom of the page you're inspecting, or in a separate window.

Exploring all that Firebug can do could be a full article of its own. But for a taste of its power, let's look at basic HTML coding. Once Firebug is activated, running your mouse over an HTML tag in the Firebug window causes a highlighted area to appear on the rendered page, showing where that tag is in the display.

Inspecting a page's HTML code.


Inspecting a page's HTML code. (Click image to see larger view)

Alternatively, you can put Firebug in Inspect mode. Then running the mouse over the rendered page causes the appropriate line of code to be highlighted. By double-clicking that code, you can edit it and see your changes on the fly. CSS works in much the same way.

For JavaScript development, Firebug finds errors and quickly jumps to where they are in the code. You can change the code and step through a script line by line, set breakpoints and so on. Essentially, it's a full-fledged JavaScript debugging system residing in a browser extension.

Firebug is a great extension and a big topic. If you develop Web pages, you'll want to add this extension to your tool kit. There's plenty of documentation and discussion of what it can do at the GetFirebug Web site.

Version reviewed: 1.01
www.getfirebug.com

Web Developer
Web Developer is another virtual Swiss Army Knife for coding. There's some overlap with Firebug, but where Firebug concerns itself almost exclusively with the content of a Web page, Web Developer offers tools to tweak how you're interacting with the page.

Web Developer's cascading menus.


Web Developer's cascading menus. (Click image to see larger view)

For instance, you can modify cookies on the fly, examining, deleting and even manually adding them. You can tweak form settings, clear private data and disable the cache -- all kinds of real-time manipulations.

Web Developer's features can be accessed as a tool bar, or as cascading menus under Firefox's Tools menu. The tool bar is particularly handy since you can see all 12 of the top-level categories of features at a glance (and, of course, it can be easily turned off when you're not in the midst of site development).

This extension can even be useful for regular Web users, thanks to features like the ability to turn off background images. If you've ever struggled to read text displayed, for example, over a background image of someone's dog, you'll appreciate this.

Web developers will probably want to run both Firebug and Web Developer, and the two extensions seem to co-exist peacefully.

Version reviewed: 1.1.3
addons.mozilla.org/firefox/60

MeasureIt
So simple and so useful. After installing this extension, you'll have a small ruler icon in your status bar. When you click on this icon, the client area of your browser window will fade out a little, and you'll have a crosshair cursor.

Use this to drag out a box over a section of the screen. Next to the box is its height and width, measured in pixels. No more guessing as to how wide a sidebar really is, or if the footer is really rendering 150 pixels deep like your style sheet says it should. When you're done, a tap of the Escape key turns off MeasureIt and gives your Web page back to you.

Measure any element on a Web page with MeasureIt.


Measure any element on a Web page with MeasureIt.

Version reviewed: 0.3.6
addons.mozilla.org/firefox/539

ColorZilla
Another quick and simple tool, this one more for designers than developers. ColorZilla puts an eyedropper icon in your status bar. Click it and you'll get a crosshair cursor. As you run this over a Web page, the RGB values of the pixel under the crosshair will display in the status bar, both as three separate values and as a hex value (e.g., R:255, G:255, B:255 | #FFFFFF).

ColorZilla shows color values in the status bar.


ColorZilla shows color values in the status bar.


More ColorZilla options.


More ColorZilla options.

Additionally, you'll get a border around the style container you're hovering over, an indicator of what the container is and what style it is using (e.g., h2.posttitle or div#content).

ColorZilla also offers a color picker, color palettes and easy access to DOM Inspector, a Mozilla tool for examining a page's Document Object Module.

Version reviewed: 1.0
addons.mozilla.org/firefox/271

So there you have it: the 20 extensions we just can't live without.

Sunday, March 18, 2007

The down side of fancies called Multiplexes..

Well last week I went to watch the movie Pursuit of Happiness, the new flick of Will Smith. This movie was running only at PVR and INOX, so called big multiplexes. I went there with my friend but didn’t get ticket bcoz they were running only 2 show per day. Despite of paying some 200 bucks you are not getting tickets of a movie show then it’s really painful. The story not ends here; I again went to watch it this weekend but still the same case. No tickets. For PVR you have an online booking system but there is no guarantee when it works and what to talk of INOX they don’t even have an online or phone booking system.
That’s why sometimes I think piracy is supported by many people. You get what you need with ease and with very less cost. Who the hell is interested to pay 200 bucks when you can easily download the real good copy of the same movie from internet using some Torrents etc. so after this incident I am happy to go to old cinema halls where they have more seats and cheaper rates and if few movies are not available in those theaters then pirated DVD’s are always there on roadsides. By the way I have got a nice and clean DivX print of this movie from net and will watch it over the weekend..

Thursday, March 08, 2007

Top 10 JSP Tips by Hans

Java Server Pages (JSP) is one of the famous tools for Java-based Web application development. A JSP page contains regular markup code plus special JSP elements. When the page is requested, the static markup code and the dynamic content produced by the JSP elements are combined to form the complete response to the request.

It's impossible to tell everything about using JSP effectively in a short article so this article focuses on the frequently asked questions that most new users look for.

1. Choosing the Right Include Mechanism

A JSP page can include page fragments from other files to form the complete response. You can use this, for instance, to keep header, footer, and navigation bar content in separate files and include them in all other pages. There are two include mechanisms: the include directive and the include action. It's not always obvious which one to use, though.

The include directive, <%@ include file="filename.inc" %>, includes the content of the specified file during the translation phase--when the page is converted to a servlet. The main page and the included file are simply merged. This means that scripting variables declared in one file (using scripting elements or an action element like ) are visible in all files and must have unique names. Some containers detect changes in files included with the directive, but the specification doesn't require it. Therefore, changes you make to the included file in a running system may not be reflected immediately; you may have to update the main JSP page, or remove the class file generated for the main page in order to see the change.

The include action, , includes the response generated by executing the specified page (a JSP page or a servlet) during the request processing phase--when the page is requested by a user. As opposed to the include directive, the page name can be specified as a so-called request-time attribute value, so which page to include can be decided when the main page is requested. Since it's the response generated by the page that is included, not the content of the page itself, scripting variables declared in one file are not available to the other files. To share an object between the pages you must instead place it in one of the following JSP scopes: request, session or application scope. If you change a page included with the include action, the change always takes effect immediately.

My rule of thumb for when to use the different mechanisms is this:

o Use the include directive if the file changes rarely. It's the fastest mechanism. If your container doesn't automatically detect changes, you can force the changes to take effect by deleting the main page class file.

o Use the include action only for content that changes often, and if which page to include cannot be decided until the main page is requested.

2. Dealing with Buffer Flushing Issues

An HTTP response message contains both headers and a body. The headers tell the browser things like what type of data the body contains (HTML text, an image), the size of the body, if the body can be cached, and so on. Headers are also used to set cookies and to tell the browser to automatically get another page (a redirect). All response headers must be sent to the browser before the body is sent.

To allow parts of the body to be produced (from static template text as well as content generated dynamically by JSP elements) before headers are set, the body is buffered. Instead of sending the response to the browser as soon as something is written to the response body, the JSP container writes all static markup code and all dynamic content generated by JSP elements to the buffer. At some point, such as when the buffer is full or the end of the page is reached, the container sends all headers that have been set followed by the buffered body content. In servlet speak, this is called committing the response. After the response has been committed, you can't set headers, such as for cookies or a redirection instruction. Another thing you can't do is forward the request to another page.

In most cases, this is not a problem. The default buffer size is 8KB, more than enough for a typical page, and you can increase it with the buffer attribute of the page directive. But if you use the include action in a page, you may be in for a surprise. Due to limitations in the way the servlet features used by are specified, the buffer is always flushed before the target page is invoked. This means that you can't set headers or use after a action.

An unfortunate side-effect of this automatic flushing is that runtime errors triggered by JSP elements after a action may not be reported correctly, since many JSP containers use the forward mechanism to display the error page. If you see an error message like "response already committed" in a page with elements, I suggest that you use the include directive instead (at least until you have isolated the problem).

3. Passing Data Between Pages Processing the Same Request

Quite often, more than one JSP page is used to process a single request. One example is when you use the include action to include a common navigation bar in all pages. Another example is when you use one page for request processing (e.g., input validation and database access) and then use the forward action, , to let another page generate the response. There are two ways to pass data from one page to another: using request parameters or request attributes.

First of all, the page invoked using a or action has access to all HTTP request parameters that were sent to the first page. In addition, you can specify new request parameters using nested actions:

value="The name or password is not valid" />

The target page has access to the all request parameters the same way, no matter if they are original or additional parameters.

Request parameters can only hold string values. If you need to pass an object, say a UserInfoBean with various user information properties, you need to pass it as a request attribute instead (or as a session or application scope bean, but let's ignore that for now). A request attribute is the same thing as a request scope object, so the first page can create the object and set all its properties with the and actions:

class="com.mycompany.UserInfoBean">

...

In order to use the bean in a page invoked through or , you must use the action in the invoked page as well. This is so that the bean created by the first page can be located and associated with the specified id. It can then be used by scripting code or other actions, such as , in the new page:

class="com.mycompany.UserInfoBean" />

4. Choosing Between Forward and Redirect

If you want to pass the control from one page to another, you can either forward to the other page, as described above, or redirect to the new page (using the sendRedirect() method of the implicit response object).

There's an important difference between a forward and a redirect. When you forward, the target page is invoked by the JSP container through an internal method call; the new page continues to process the same request and the browser is not aware of the fact that more than one page is involved. A redirect, on the other hand, means that the first page tells the browser to make a new request to the target page. The URL shown in the browser therefore changes to the URL of the new page when you redirect, but stays unchanged when you use forward. A redirect is slower than a forward because the browser has to make a new request. Another difference is that request scope objects are no longer available after a redirect because it results in a new request. If you need to pass data to the page you redirect to, you have to use a query string and pass them as request parameters (or save the data as session or application scope objects).

So how do you decide if you should use forward or redirect? I look at it like this: Forwarding is always faster, so that's the first choice. But since the URL in the browser refers to the start page even after the forward, I ask myself what happens if the user reloads the page (or just resizes the window; this often reloads the page automatically). If the start page is a page that updates some information, such as adding an item to the shopping cart or inserting information in a database, I don't want it to be invoked again on a reload. To show the result of the processing, I therefore redirect to a page with a confirmation message, instead of using forward.

5. Choosing Between Beans and Custom Actions

In JSP 1.0, JavaBeans were the only type of components that you could use to encapsulate the Java code and invoke using standard JSP action elements, such as and . JSP 1.1 adds custom action elements to the component toolbox. A Java class, called a tag handler, implements a custom action's behavior. In its most simple form, it's just a JavaBeans class with property access methods corresponding to the custom action elements plus a few extra methods used by the container to invoke the tag handler (so it can do its job). Tag handlers that need to process the element's body or create objects assigned to scripting variables requires a bit more effort to develop, but it's still not rocket science. It is, however, too much to describe in detail here. My book contains two chapters with all the details about how to develop custom action tag handlers.

As is often the case in software development, it's hard to say exactly when a bean or a custom action is the preferred component type. My rule of thumb is that a bean is a great carrier of information and a custom action is great for processing information. Custom actions can use beans as input and output. For instance, you can use a bean to capture form input, with the action, and then a custom action to save the properties of the bean in a database. The reverse is also a good example; get information from a database using a custom action that makes it available to the page as a bean.

6. Using Packages for Bean Classes

When you develop a bean to be used in a JSP page, I recommend that you make it part of a named package. A Java class that does not use a package statement ends up in the so-called unnamed package. The servlet class generated from the JSP page is, however, typically assigned to a named package. If you try to refer to a class in the unnamed package from a class in a named package, Java cannot find the class unless you use an import statement to import it. In a JSP page that means you must use both a page directive to import the class, and the action to make it available:

<%@ page import="UserInfoBean" %>

If the bean is part of a named packed, the action is all you need:

class="com.mycompany.UserInfoBean" />

7. Mixing Scripting Variables and Scope Variables

My general advice is that you avoid embedding Java code in your JSP pages. Code in scripting elements can easily lead to hard to find syntax errors and too much code in the pages makes the Web application hard to maintain. One specific area of confusion when you use both Java code scriptlets and JSP action elements is how scripting variables and objects created by an action element in a JSP scope interact. Or rather, don't interact. Consider this example:

class="com.mycompany.UserInfoBean" >

<%

userInfo = new com.mycompany.UserInfoBean();

%>

Here a UserInfoBean instance is created by the action in the page scope (default) and its firstName property is set to the value passed as a request parameter with the same name. The also makes the bean available as a scripting variable with the same name as the scope variable (userInfo in this example). Next, a scriptlet creates a new instance of the UserInfoBean class and assigns it to the userInfo scripting variable. Finally, the action retrieves the value of the bean's firstName property. But which instance of the UserInfoBean does use? The answer is the instance available in the page scope. The action, or any action element for that matter, cannot access scripting variables, only objects placed in one of the standard JSP scopes: page, request, session and application. If you must use scripting elements to create objects that you then want to let actions access, you must also place them in the appropriate scope:

...

<%

userInfo = new com.mycompany.UserInfoBean();

pageContext.setAttribute("userInfo", userInfo);

%>

property="firstName" />

In this modified example, the setAttribute() method is used to replace the page scope object created by with the instance created by the scriptlet. Hence, the action finds the new instance.

8. Setting Properties to Non-String Data Type Values

Bean properties, as you probably know, are represented by accessor methods: a setter method for a writeable property and a getter method for a readable property. The data type of the property is the data type of the setter method's single argument and the getter methods return type.

The action is often used to set a bean's property to the values of request parameters. Request parameters are sent as strings, so what happens if the bean's properties are of other types than String? The JSP container is nice enough to convert String values to the most commonly used Java data types, as described in the following table:

Property TypeConversion Method boolean or BooleanBoolean.valueOf(String) byte or ByteByte.valueOf(String) char or CharacterString.charAt(int) double or DoubleDouble.valueOf(String) int or IntegerInteger.valueOf(String) float or FloatFloat.valueOf(String) long or LongLong.valueOf(String)

If your property is of a type not listed in the table, you need to take care of the conversion yourself. The most author-friendly way is to use a String property, even for properties that logically should be of a different type, such as a date or a RGB color value, and let the bean convert it internally. But if you really want to use a data type other than String or the ones listed above, the page author can use a request-time attribute value that evaluates to the correct data type to set the property value:

value='<%= new

java.util.Date(request.getParameter("empDate")) %>' />

Note that this example uses a deprecated Date constructor and is very error-prone (it fails if the empDate parameter is missing or doesn't hold a valid date string). I use it only to illustrate how you can set an attribute of a data type that has no JSP-supported conversion rule, such as the Date class used here.

The rules described here for bean properties set by also applies to custom action attributes.

9. Accessing a Database

One of the most frequently asked questions on Sun Microsystem's JSP-INTEREST mailing list is how to access a database from a JSP page. I'm sorry, but a complete description is out of scope for this article. I can give you some guidelines, though.

JSP is Java, so as in all Java programs, you'd use JDBC to access a database. You can read more about the JDBC API here.

I recommend that you do not put the database access code directly in the JSP page. Instead, create a bean or a custom action that does all the hard work. My book contains a set of custom actions for database access that you can use, and there are many other examples available on the Net (see Tip 10 of this article). For a complex application, you may actually want to use a servlet for all database access and let it forward the request to a JSP page that only deals with rendering the result. This model is often referred to as the Model-View-Controller (MVC) model, or Model 2 (a term used in a prerelease of the JSP specification). I show examples of this alternative in my book as well. You can also learn more about the MVC model from the Apache Struts project.

Database access is typically very expensive in terms of server resources. You should use a connection pool (covered in the book and frequently discussed on the JSP-INTEREST list) to share database connections efficiently between all requests. Another resource saver is to cache the results of database queries as much as possible. In many cases, the database information rarely changes. For instance, product catalog information may change only when products are added or deleted, or when the prices change. For this type of information you can get the data once and save it as an application scope object that all users can access. In the rare event that the information changes, just replace the application scope object with a new version. Another caching strategy for data that changes infrequently is to cache it as a session scope object. The user will then see the data as it looks when the session starts, but changes made during the session are not visible. If you use the session cache strategy, you must also consider if the amount of memory used for the cache (one copy per session) is worth the gain in reduced number of database accesses. Typically it is worth it, but make sure your server has enough memory to handle the peaks.

If you decide to use a cache, don't use the JDBC ResultSet object itself as the cache object. A ResultSet is tightly linked to a specific connection and therefore conflicts with the connection pooling. Instead, copy the data from the ResultSet into an application specific bean, a Vector of Vector's, or something similar.

10. Finding out More

I hope you have found something in this article that helps you develop your JSP based application. But there's a lot more you should know to use this powerful technology as efficiently as possible. I recommend, you read Han’s book on, JavaServer Pages (O'Reilly).

There's also plenty of information on the Internet. The best place to start Sun's JSP page. There you find the JSP specification, articles and tutorials written by Sun employees, and lots of references to other JSP-related sites and products.

Popular Posts