13.07.2015 Views

Software Engineering for Internet Applications - Student Community

Software Engineering for Internet Applications - Student Community

Software Engineering for Internet Applications - Student Community

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.10 Choosing between GET and POSTFollowing an ordinary hyperlink on an HTML page results in a GETrequest to the server under the HTTP protocol. When programming apage with an HTML <strong>for</strong>m you have a choice between usingMETHOD=GET and METHOD=POST. A heavy reliance on POST willresult in a site that breaks the browser Back button. An attempt to goback to a page that was the result of a POST will generally bring up a"Page Expired" error message and possibly a dialog box askingwhether the user wishes to resubmit in<strong>for</strong>mation by using the"Refresh" button.Some of our students asked <strong>for</strong> further guidance on how to choosebetween GET and POST and here's the response from Ben Adida,part of the course's teaching staff in Fall 2003:Most of you may be wondering, why GET vs. POST insubmitting <strong>for</strong>ms? Oftentimes, one will use POST just tokeep pretty URLs (without ?var=val&var=val). But that'sthe wrong way to think about it.A GET implies that you are getting in<strong>for</strong>mation. You canresubmit a GET any number of times: you are justquerying in<strong>for</strong>mation, not per<strong>for</strong>ming any actions on theback-end.A POST implies that you are per<strong>for</strong>ming some action withside-effect: inserting a row, updating a row, launching amissile, etc... That's why when you try to reload a POSTpage, your browser warns you: are you sure you want tolaunch another missile?In general, you should strive to respect the aboveprinciples. Here are two key examples:- searching users or content. That should be a GET.- Inserting a user or updating a profile.That should be a POST.Of course, HTML and HTTP have some restrictions thatcomplicate things:a) GET <strong>for</strong>ms are limited in length by how much yourbrowser can send in a URL field. This can be a problem<strong>for</strong> very complicated search <strong>for</strong>ms, though probably notan issue at this stage. If you do hit that limitthough, then it's okay to use a POST.b) POST <strong>for</strong>ms can only be per<strong>for</strong>med by having an HTML90stopwords list of exceedingly common English words such as "the","and", "or", etc. Whatever full-text search tool that you used in theSearch chapter probably contains such a list somewhere in a filesystem file or a database table. You can use the top few words in thislist to query Amazon <strong>for</strong> a list of matching titles.For the purpose of this exercise you can fetch your Amazon data onevery page load. In practice on a production site this would be bad<strong>for</strong> your users due to the extra latency and bad <strong>for</strong> your relationshipwith Amazon because you might be per<strong>for</strong>ming the same queryagainst their services several times per second. You'd probablydecide to store the related books in your local database, along with a"last message" stamp and rebuild periodically if there were newreplies to a thread.Each related book should have a link to the product page onAmazon.com, optionally keyed with an Amazon Associates ID. Here'san example reference:BasicPhotographic Materials and ProcessesThe ISBN goes after the "ASIN", and the Associates ID in thisexample is "photonet", which is suffixed with an "A".14.6 Exercise 5: What's New PageIf you don't already have one, build an HTML page that lists the 10most recently added content items in your community. For eachcontent item display the following:• title or one-line summary• A text summary of the content or, if appropriate, the contentitself• The name of the person that created the item, hyperlinkedto that person's user profile page• The time the item was created (RFC 822 <strong>for</strong>mat, precise tothe second, e.g. Wed, 29 Oct 2003 00:09:19 GMT).Make this page available at new-content in a directory of yourchoice. Note that it should be easy to build this page using a function259

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!