Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Httpunit和servlet单元测试servlet中包含jstl代码的jsp页面_Jsp_Unit Testing_Jstl_Http Unit_Servletunit - Fatal编程技术网

使用Httpunit和servlet单元测试servlet中包含jstl代码的jsp页面

使用Httpunit和servlet单元测试servlet中包含jstl代码的jsp页面,jsp,unit-testing,jstl,http-unit,servletunit,Jsp,Unit Testing,Jstl,Http Unit,Servletunit,我试图使用HttpUnitServlet runner测试以下servlet代码。在这里,除了包含jstl的jsp页面之外,一切都很顺利 public class ListTenantServlet extends HttpServlet { private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(ListTenantServlet.class

我试图使用HttpUnitServlet runner测试以下servlet代码。在这里,除了包含jstl的jsp页面之外,一切都很顺利

public class ListTenantServlet extends HttpServlet {

  private static final long serialVersionUID = 1L;
  private static final Logger log = Logger.getLogger(ListTenantServlet.class.getName());

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {

    doProcess(req, res);
  }

  public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {

    doProcess(req, res);
  }

  private void doProcess(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
       CompanyStatus companyStatus = TenantStatus.Paid;
       req.setAttribute("companyStatus" companyStatus);
       RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/tenantList.jsp");
       dispatcher.forward(req, res);
  }
如果我尝试测试上面的代码,则会出现以下异常,但servlet在本地服务器中工作正常

HTTP请求错误:500 org.apache.jasper.jaspereException:绝对uri:无法在web.xml或与此应用程序一起部署的jar文件中解析[http://localhost/contextParam/tenantmgr/listTenant]

注意:我的ListTenant.jsp包含jstl代码,如果删除jstl代码,测试工作正常


请帮我把它弄好

有点晚了,但是,您需要为servlet单元提供一些jar。起初,大部分时间都没有。一个很好的解决方案就是从本地服务器复制相同的jar,例如,如果您使用的是tomcat,则使用tomcat_HOME/lib/*.jar

我已经使用ServletUnit+Spring+Maven自动化了JSP测试,并添加了一些依赖项,看看我的答案