1:超简单的Servlet 程序
HelloWorld.java
package com.myHelloWorld;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorld extends HttpServlet ... {
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException...{
PrintWriter out = response.getWriter();
out.write("<html> ");
out.write("<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> ");
out.write("</head> ");
out.write(" ");
out.write("<body> ");
out.write("<font size=20> ");
out.write("Servlet to HelloWorld");
out.write(" ");
out.write("</font> ");
out.write("</body> ");
out.write("</html>");
}
}
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorld extends HttpServlet ... {
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException...{
PrintWriter out = response.getWriter();
out.write("<html> ");
out.write("<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> ");
out.write("</head> ");
out.write(" ");
out.write("<body> ");
out.write("<font size=20> ");
out.write("Servlet to HelloWorld");
out.write(" ");
out.write("</font> ");
out.write("</body> ");
out.write("</html>");
}
}
web.xml