servlet简单实例

< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>

package com;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;


public class servletTest extends HttpServlet ...{
    
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException ...{
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        //TODO output your page here
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet servletTest</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet servletTest at " + request.getContextPath () + "</h1>");
        out.println("<body>");
        out.println(getServletInfo());
        out.println("</html>");
         //
        out.close();
    }
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException ...{
        processRequest(request, response);
    }
    
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException ...{
        processRequest(request, response);
    }
    
    
    public String getServletInfo() ...{
        return "Short description";
    }
    // </editor-fold>
}

 

posted @ 2012-07-03 13:22  netcorner  阅读(260)  评论(0编辑  收藏  举报