怎么用JUnit3测试servlet-CSDN论坛
1个回答
展开全部
ServletRunner sr=new ServletRunner();//创建servlet运行环境
sr.registerServlet("/login.do", ServletAction.class.getName());//向环境中注册servlet
ServletUnitClient sc=sr.newClient();//创建访问servlet客服端
WebRequest request=new PostMethodWebRequest//发送请求
request.setParameter("userName", "droba");
request.setParameter("password", "123");
InvocationContext ic = sc.newInvocation(request);//获得请求的上下文环境
ServletAction sa=(ServletAction) ic.getServlet();//调用servlet非服务方法
WebResponse response=sc.getResponse(request);
sr.registerServlet("/login.do", ServletAction.class.getName());//向环境中注册servlet
ServletUnitClient sc=sr.newClient();//创建访问servlet客服端
WebRequest request=new PostMethodWebRequest//发送请求
request.setParameter("userName", "droba");
request.setParameter("password", "123");
InvocationContext ic = sc.newInvocation(request);//获得请求的上下文环境
ServletAction sa=(ServletAction) ic.getServlet();//调用servlet非服务方法
WebResponse response=sc.getResponse(request);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询