140 likes | 320 Views
Dynamic Web Applications. CS 4720 – Web & Mobile Systems. Last Week. We know what servers are Apache: standard web server that sends files MySQL: database server that sends formatted data Tomcat: web server that rolls in a Java compiler We know what our clients are looking for
E N D
Dynamic Web Applications CS 4720 – Web & Mobile Systems
Last Week • We know what servers are • Apache: standard web server that sends files • MySQL: database server that sends formatted data • Tomcat: web server that rolls in a Java compiler • We know what our clients are looking for • Browsers want HTML • Stand-alone clients want whatever we tell them to want 2
Dynamic-ness... ish. • Plain HTML is fine for plain websites where information never changes • (That's so 1999.) • A dynamic website is one where the webpage changes based on: • Browser input (post, get) • Session variables (information stored in browser) • Stored variables (cookies) • Other (time of day, location, etc.) 3
Dynamic-ness... ish. • We have to remember that even though this is a “dynamic” website, there is still a server/client, call/response going on here • Image courtesey websiteoptimization.com 4
Dynamic-ness... ish. • We provide a set of variables to the server and an HTML page is generated on the fly according to those variables • Think of it this way: it's like a standard Java console app that you'veprogrammed before, but the output now has to be HTML 5
PHP • PHP: Hypertext Preprocessor • Actually, it originally stood for “personal home page” • Scripting / interpreted language • Useful for both web sites and for stand-alone scripts (like perl) • Latest version even includes objects! 6
Acceptance of PHP • PHP has become a widely used web programming language • Specific PHP modules have been created for: • Nearly every web server software system • MySQL (works REALLY well together) • Other database systems • Windows API extensions • Many compression formats 7
Why do I like it? • It's easy to setup • It's rare to find stuff for a linux server that “just works” • It's easy / comfortable to code it • Java-like syntax, with none of the hassles • Powerful • You can do a lot of interesting things with PHP • Fast (to code and to run) • Compare this with JSP when we get to it… 8
PHP for Java Developers • Dynamic typing • A method can return a boolean on one line and a String on the next • All variables start with $ • You use -> for methods in objects, not . • You use . for concatenation, not + • “” and ''work very similarly • Strings can contain variables and are dynamically replaced at runtime 9
PHP for Java developers • In an HTML page, a php section starts with <?php and ends with ?> • If error printing isn't turned on on the server, you'llhave to deal with the white screen of death • Remember that here you're output has to be HTML! • i.e. to drop a line, echo <br/> • Other than that, some keyword changes 10
W3Schools • http://www.w3schools.com/php/default.asp • Great website for quick tutorials about a lot of web stuff • Look at some of the tutorials here • (Also http://www.phpclasses.org/) 11
PHP and Forms • One of the biggest uses of PHP is interpreting HTML forms • PHP can pull the data out of the returned fields and use them as variables • It can then: • Print them • Store them to a database (or other file) • Use them to generate other content • Post vs. Get 12
PHP and Forms • Build two pages: • A PHP file that will determine whether or not a user has posted a comment to this site by looking for a cookie • If they haven't posted, the user should see an HTML form that will asks them to post their name and a comment; otherwise, thank them for the comment • A PHP file that will take the results of the form submission, print it to the screen, and make a cookie on the user's machine indicating they have left a comment 13
JSP • So, how is JSP different? • Let's look at JSP syntax… 14