【问题标题】:Test the jsp pages which includes jstl code in servlet using Httpunit and Servlet unit使用Httpunit和Servlet单元测试在servlet中包含jstl代码的jsp页面
【发布时间】:2013-09-21 11:50:59
【问题描述】:

我正在尝试使用 httpunit servlet 运行程序测试以下 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.JasperException:绝对 uri:http://java.sun.com/jsp/jstl/core 无法在 web.xml 或使用此应用程序部署的 jar 文件中解析 [http://localhost/contextParam/tenantmgr /listTenant]

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

请帮助我使它工作。

【问题讨论】:

    标签: jsp unit-testing jstl http-unit servletunit


    【解决方案1】:

    有点晚了,但是,您需要为 servlet 单元放置一些可用的 jar。起初它没有大部分。一个不错的解决方案,它只是从本地服务器复制相同的 jar,例如。如果你使用的是 tomcat TOMCAT_HOME/lib/*.jar。

    我已经使用 ServletUnit+Spring+Maven 自动执行 JSP 测试并添加了一些依赖项,请看我的回答 here

    【讨论】:

      猜你喜欢
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 2016-04-15
      • 1970-01-01
      • 2012-11-09
      • 2011-02-03
      • 1970-01-01
      • 2014-03-25
      相关资源
      最近更新 更多