Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

create a web app in java (a web server program) that tells the user (whos viewing the resulting webpage in a browser) a knock-knock joke.

create a web app in java (a web server program) that tells the user (whos viewing the resulting webpage in a browser) a knock-knock joke. This will involve creating a simple web server program like in class (i.e., a program listening on a given tcp port 8080 that then, whenever a new request arrives, talks in http over the resulting socket with the sender of that request) that asks the users a knock-knock joke over a series of http request/response roundtrips. This will involve generating html (in particular simple html forms), get parameters, and cookies.

Entry from form = get params!

Which step / if error mode = cookies!

Define a cookie (named, say, state) that encodes what step of the joke-telling process you are in. (A cookie, not a Java var, because multiple users (webbrowsers) can simultaneously be on different steps with the server.)

Details (more to come):

First visit to the page (e.g. localhost:8080)

(example logic: state = 0, or state cookie doesnt exist)

return an html page (the message Knock knock! and an html form with a text entry box and a submit button) and set state cookie to (say) 1 in http response header

Entering Whos there?

(state = 1) a message with NAMEOFWHOSTHERE and another text box/button form (and set state cookie to 2)

Entering anything else an error message telling them theyre supposed to say Whos there? and the form again

Entering NAMEOFWHOSTHERE + who?

(state = 2)

Entering anything else similar error behavior

Message with NAMOFWHOSTHEREWHO, and a start over button (and reset state cooke to 0)

Pressing button original screen

Servers logic upon receiving new http request:

read state cookie, it should be 0/1/2 or missing (treat missing as being 0)

read get param text (either the string that the user entered, or missing)

if state == 0/missing:

return KNOCKKNOCK webpage, with state set to 1 in header

if state == 1:

if text case-insens-equals whos there?:

return NAMEOFWHO webpage, setting state to 2 in header

else:

return KNOCKKNOCKAGAIN webpage,

setting state to 1 (no change) in header

if state == 2:

if text case-insens-equals NAMEOFWHO who?:

return WHOLEFUNNYNAME webpage

(with no text entry box, just a start over button),

setting state to 0 in header

else:

return NAMOFWHOSTHERWHOAGAIN webpage,

setting state to 2 (no change) in header

KNOCKKNOCKAGAIN webpage: same as KNOCK KNOCK webpage, except complaining that they didnt correctly enter whos there? like theyre supposed to.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions