簡體   English   中英

使用時出現錯誤404 <c:import> JSTL標記以將HTML文件導入JSP的另一個文件夾中

[英]Error 404 when using the <c:import> JSTL tag to import an HTML file in another folder in a JSP

我正在嘗試將我在JSP中制作的HTML文件包括在內,但遇到一個奇怪的錯誤,我認為這與文件所在的路徑有關。 我正在使用IntelliJ IDEA並正在開發Google App Engine。

我的問題是使用標簽時:

<c:import url="/HTML/sidebar.html"/>

該頁面看起來像這樣

錯誤404 /JSP/JSP/FrontPage.jsp

這就是內容!!

當我不使用import標簽時,頁面就會生成並簡單地說

這就是內容!!


我的網站目錄如下所示:

  • 卷筒紙
    • CSS
    • HTML
      • sidebar.html
    • JSP
      • FrontPage.jsp
    • WEB-INF

FrontPage.jsp中,我具有以下內容:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>

<body>
      <div class="sidebar">
          <c:import url="/HTML/sidebar.html"/>
      </div>
      <div class="content">
          this is the content!!
      </div>
</body>
</html>

sidebar.html文件非常基礎:

<ul>
  <li>Home</li>
  <li>Blog</li>
  <li>Projects</li>
  <li>Contact</li>
</ul>

最后,我可以通過服務器來處理到目前為止只有doGet方法的首頁:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("On Front Page!");
    request.getRequestDispatcher("JSP/FrontPage.jsp").forward(request,response);
}

更新 :我在eclipse中嘗試了文件和相同的Web目錄,並且它起作用了,因此IntelliJ必須有所不同。 誰能解釋一下如何在IntelliJ中完成這項工作? 謝謝!

<c:import>標記用作

<c:import url="HTML/sidebar.html"/>

由於該標記可以從應用程序上下文外部導入,因此前導/會引起問題。 指定的路徑是相對於當前正在處理的URL請求的路徑; 因此,請相應地進行調整。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM