【问题标题】:Why does the existence of web.xml keep my JSP from working?为什么 web.xml 的存在使我的 JSP 无法正常工作?
【发布时间】:2013-02-13 01:05:49
【问题描述】:

我有一个如下所示的 jsp 文件:

<html>
<body>
    <div>location: ${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/</div>
    <div>(should have "verdagon.net" somewhere in there)</div>

    <div>Included stuff should appear below here:</div>
    <jsp:include page="toinclude.html"/>
</body>
</html>

当我的 WEB-INF 目录中没有 web.xml 时,它会正确输出:

location: http://verdagon.net:80/strnowebxml/
(should have "verdagon.net" somewhere in there)
Included stuff should appear below here:
I'm included!

然而,当我添加一个 WEB-INF 目录时,我放了一个简单的 web.xml,里面只有这个,

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
</web-app>

随着 web.xml 的出现,我得到了这个输出:

location: ${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/
(should have "verdagon.net" somewhere in there)
Included stuff should appear below here:
I'm included!

问题:这些美元符号替换没有发生。

奇怪的事情:我知道 JSP 正在运行,因为 jsp:include 运行良好。

任何人都知道为什么 JSP 在没有 web.xml 时工作,然后在我添加它时中断?

【问题讨论】:

  • 尝试在您的 JSP 中使用以下内容:&lt;%@ page isELIgnored="false" %&gt; 看看是否可行。我假设当您使用web.xml 时,此属性默认为true

标签: jsp tomcat


【解决方案1】:

啊哈!原来是版本不匹配。全局 web.xml,在 tomcat/conf/web.xml 中,顶行为:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

但我的顶线是

<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

答案:版本不同!最高的是 2.4,最低的是 3.0。一旦我将我的 3.0 更改为 2.4,替换就会正常进行。

(对于遇到类似问题的其他人,这些答案可能会对您有所帮助:)

EL is not interpreted and appears plain vanilla in generated HTML output

Expression Language in JSP not working

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 2021-12-30
    • 2020-06-27
    • 2021-04-03
    • 1970-01-01
    相关资源
    最近更新 更多