與 Tomcat 整合:Hello.py

程式碼

# -*- coding: utf-8 -*- import cgi import time def htmlHeader(): print "Content-type: text/html\n\n" print "<html><body>\n" def htmlBody(): currTime = time.strftime("%H:%M:%S") callerForm = cgi.FieldStorage() myFName = callerForm["myFName"].value myLName = callerForm["myLName"].value print "<p><h3>Hello <font color='red'>%s %s</font>, It is <font color='blue'>%s</font>!\n</h3></p>" % (myFName, myLName, currTime) def htmlTail(): print "<a href='#' onclick='history.go(-1); return false;'>%s</a>" % ("Go Back") print "</body></html>\n" htmlHeader() htmlBody() htmlTail()