在移植这个程序几个小时之后,它似乎终于进入了工作状态。然而,我想知道是否有人知道将javaservlets移植到Python中的更好或更完整的方法。Python脚本的开头包含了许多支持代码,以便于将程序逐行直接移植到Python中。有人知道更好的办法吗?在
Java// --------------------------------------------------------
// File: Hello.java
// Description: A simple "Hello World" servlet
// --------------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import sun.servlet.http.HttpServer;
public class Hello extends HttpServlet {
int count;
public void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// setup response
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// send response
out.println("
");out.println("
Stephen Paul Chappell (SPC)
");out.println("
:) (ZTD) Zero The Dragon :(
");String name = request.getParameter("NAME");
if (name != null && !name.equals("")) {
out.println("
Hello, " + name + "
");} else {
out.println();
if (name != null && name.equals("")) {
out.println("
You didn't enter your name. Please enter your name.
");} else {
out.println("
What's your name?
");}
out.println("
");
out.println("
");out.println();
out.println(" Enter your name:
");
out.println(" ");
out.println();
out.println("
");}
String color = request.getParameter("FAVCOLOR");
if (color != null) {
out.println("
Why, " + color + " is my favorite color too!
");}
count++;
out.println("This page has been hit " + count + " time(s).");
out.print("");
}
// start web server
public static void main(String[] args) throws Exception {
HttpServer.main(args);
}
}
Python
^{pr2}$
如果有人想知道这个项目的目的是什么,最初的Java程序是作为一个新生级计算机科学课程的入门练习。从那时起,我已经有六年没有使用Java了,我正在研究旧的程序,将它们移植到Python上,以应对挑战和学习体验。移植servlet会带来额外的困难。在