【问题标题】:link from html to jsp从html链接到jsp
【发布时间】:2012-07-31 13:23:05
【问题描述】:

在动态 Web 项目中我有 - default.html 页面

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="./Styles/Site.css" type="text/css" />
<title>Create new customer</title>
</head>
<body>
    <a href="\WEB-INF\forms\CustomerMenu.jsp">Test new</a>

</body>
</html>

我也有 CustomerMenu.jsp 页面 -

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="./Styles/Site.css" type="text/css" />
<title>Create new customer</title>
</head>
<body>
    // Table ..
</body>
</html>

页面层次结构就像快照 -

当我点击 default.html 中的链接时,我收到错误消息

- HTTP Status 404 - 

--------------------------------------------------------------------------------

type Status report

message 

description The requested resource () is not available.

【问题讨论】:

    标签: java html jsp href


    【解决方案1】:

    /WEB-INF 文件夹中的文件不能公开访问,除非使用前端控制器 servlet 或像 &lt;jsp:include&gt; 这样的特定标签,该标签执行 RequestDispatcher#forward()RequestDispatcher#include()

    如果您需要通过 URL直接 访问 JSP 文件,那么您不应该将 JSP 放在 /WEB-INF 文件夹中。将其放在/WEB-INF 文件夹之外

    WebContent
     |-- forms
     |    |-- CreateNewCustomer.html
     |    |-- CustomerMenu.html
     |    `-- CustomerMenu.jsp
     |-- WEB-INF
     :    :
    

    并相应地修复链接。

    <a href="forms/CustomerMenu.jsp">Test new</a>
    

    【讨论】:

    • 只是 BalusC 的一个重点说,如果 /WEB-INF 文件夹作为 Web 容器的一部分受保护,这就是为什么所有 Web 资产 - 图像、css、js ...... t 包括在内。
    • @BalusC , WebContent 中的文件夹必须叫“forms” ?
    • 没有。这正是 you 最初的称呼。我只是没碰它。我所做的只是将文件夹移动到正确的位置。只要它是可公开访问的,您就可以随意命名/构造它。您甚至可以完全摆脱它,只需将其文件直接放在根文件夹中(WebContent 文件夹,default.html 文件也在其中)。
    【解决方案2】:

    WEB-INF 文件夹在外部无法访问。 您要么需要将 jsp 移到 WEB-INF 之外,要么使用转发请求转发到 jsp。

    【讨论】:

      猜你喜欢
      • 2013-05-21
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      相关资源
      最近更新 更多