【问题标题】:jsp page doesn't appears?jsp页面没有出现?
【发布时间】:2020-03-25 17:58:54
【问题描述】:

我的工作包括使用 servlet 查看 JSP 页面,问题是 Produit.jsp 正常工作,但它不适用于 SaisieProduit.jsp(所以这不是 web.xml 的问题),还有什么时候我运行 SaisieProduit.jsp 没有通过它正常工作的 servlet 类。

这是我的 servlet 类

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String path=req.getServletPath();

        if(path.equals("/index.do")){
            req.getRequestDispatcher("produits.jsp").forward(req, resp);
        }
        else if(path.equals("/chercher.do")){
            String motCle=req.getParameter("motCle");

            ProduitModel model=new ProduitModel();
            model.setMotCle(motCle);            
            List<Produit> produits=new ArrayList<Produit>();
             produits=metier.produitsParMC(motCle);
            model.setProduits(produits);
            req.setAttribute("model", model);
            req.getRequestDispatcher("produits.jsp").forward(req, resp);

        }

        else if(path.equals("/saisie.do")){
            req.getRequestDispatcher("SaisieProduit.jsp").forward(req, resp);
        }



    }

}

这里是saisie.do的链接

<div class="navbar navbar-default">
  <ul class="nav navbar-nav">
  <li><a href="index.do">Home</a></li>
  <li><a href="saisie.do">Saisie</a></li>
</ul>

</div>

当我点击 saisie 时,会出现一个总括页面

【问题讨论】:

    标签: java jsp jakarta-ee


    【解决方案1】:

    我猜是String path=req.getServletPath(); 只会打印您在 servlet 中设置的 URL,因此您尝试使用的条件不会触发。打印你的路径变量,你可以检查一下。

    这是我理解您正在尝试做的事情的一种方法:call servlet on link

    【讨论】:

      猜你喜欢
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 2019-01-01
      相关资源
      最近更新 更多