junit对servlet,session的模拟

来源:互联网 发布:java需要学网络编程 编辑:程序博客网 时间:2024/05/16 06:48

     String []params={"RESET_CONN_MON","CLOSE_ONLINE","OPEN_ONLINE"};

 ServletRunner sr = new ServletRunner();
      sr.registerServlet( "CommandServlet", CommandServlet.class.getName() );
    ServletUnitClient  sc = sr.newClient();
    WebRequest     request   = new GetMethodWebRequest( "http://localhost/CommandServlet" );

      request.setParameter("cmd",params);
       InvocationContext  ic = sc.newInvocation(request);
       CommandServlet  is = (CommandServlet)ic.getServlet();

   is.doGet(ic.getRequest(), ic.getResponse());