COMP249 Web Technology
Tutorial - Week 6
Answer the following questions and hand in your answers in a text file via WebCT before 9am Monday 31st March.
- What part of the HTTP header is always provided as part of the response of a CGI program? Why?
- How does the HTML form element specify which CGI program will process the form data? What other attributes does the form have to control how the data is submitted?
- Write a Python script which does the following:
- If there is no user input, generate a form which asks for the user's name and email address. The action of the form should be this script.
- If there is user input, returns an HTML page saying "Thanks for subscribing, your details are: USERNAME, EMAIL"
- Do you think it is necessary for client-side data validation before the data is transferred to server-side programs? Why? Write the HTML page with Javascript validation of USERNAME and EMAIL, which invokes the above python program if the validation is successful.
Additional topics for discussion in the tutorial (not for handing in):
- Describe what the following function does:
def mystery(x): d = dict() s = x.split() for w in s: if len(w) > 3: if d.has_key(w): d[w] += 1 else: d[w] = 1 return d - Can you suggest a good way to test a CGI script? If you have written a complex script (say for a banking system) how would you ensure that it was doing the right thing and that it could cope with all expected input?