文档介绍:作者:何志强 email: hhzqq@ 日期:2000-8-10 17:07:04 /* 作者:何志强[hhzqq@] 日期:2000-08-10 版本: 功能:Servlet基础例程- HelloServlet */ import .*; import .*; //MessageFormat import .*; import .*; public class HelloServlet extends HttpServlet{ //页面标题 protected static final String strTitle = "Servlet基础例程- HelloServlet"; //页眉 protected static final String strHeader = ""+ ""+ ""+ ""+ ""+ ""; //页脚 protected static final String strFooter = ""+ ""; //表单 protected static final String strForm = "
"+ "您尊姓大名: "+ "\"提交\""+ "
"; protected static final String strHello = "您好,{0},欢迎来到Servlet/JSP世界!"; //出错信息 protected static final String strError = "
{0}
"; protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{ process(req,resp); } protected void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{ process(req,resp); } protected void process(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{ try{ String submit = ("submit"); if(submit==null) printForm(req,resp); else printHello(req,resp); } catch(Exception e){ printError((),req,resp); } } protected void printForm(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{ //在使用PrintWriter前得先设置Content Type ("text/html")