java Weblogic 抛出 CompilationException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3141410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:32:37  来源:igfitidea点击:

Weblogic throws CompilationException

javajspjakarta-eeweblogic

提问by Enno

javax.servlet.ServletException: weblogic.servlet.jsp.CompilationException: Failed to compile JSP /WEB-INF/content/intro.jsp
messages.tag:2:30: The encoding specified on the page cannot be different than detected encoding for the file.
<%@ tag body-content="empty" pageEncoding="utf-8" %>
                             ^----------^

If I remove pageEncoding attribute in tag file, it works. But I think this is not a solution, because it already works on another Weblogic server. So the problem is with my Weblogic configuration. By Googling the error, I did not found anything.

如果我删除标签文件中的 pageEncoding 属性,它就可以工作。但我认为这不是一个解决方案,因为它已经在另一个 Weblogic 服务器上运行了。所以问题出在我的 Weblogic 配置上。通过谷歌搜索错误,我没有发现任何东西。

Any ideas? I have tried setting encoding to UTF-8 in weblogic.xml and many other things I can't even remember, I have had this issue for some time now.

有任何想法吗?我曾尝试在 weblogic.xml 中将编码设置为 UTF-8 以及许多其他我什至不记得的事情,我遇到这个问题已经有一段时间了。

回答by Karthik N

WebLogicexpects strict encoding. So add the page encoding tagas the first declaration before any other declarations in the jsp. It solved the problem for me.

WebLogic需要严格的编码。因此,在jsp 中的任何其他声明之前添加页面编码标记作为第一个声明。它为我解决了这个问题。

From:

从:

<%@ page import="com.abc.xyz.Helperjsp"%> <%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>

<%@ page import="com.abc.xyz.Helperjsp"%> <%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>

To:

到:

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> <%@ page import="com.abc.xyz.Helperjsp"%>

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> <%@ page import="com.abc.xyz.Helperjsp"%>

回答by matt b

Make sure that the contents of /WEB-INF/content/intro.jsp are also UTF-8 encoded.

确保 /WEB-INF/content/intro.jsp 的内容也是 UTF-8 编码的。

回答by ADTC

Expanding on KarthikN's answerand my own comment.

扩展 KarthikN 的回答和我自己的评论

It must be noted that the important point is that the directive containing the pageEncodingmust be the first declarationon your JSP page. As stated in my comment:

必须注意,重要的一点是包含 的指令pageEncoding必须是JSP 页面上的第一个声明。正如我的评论中所述:

It's more than just rearranging those two lines. Actually, it's not even a rearrangement, but more like moving that directive to the very top of everything else. [...] That means you cannot have JSP blocks, JSP directives, JSP comments or anything before that.

这不仅仅是重新排列这两行。实际上,它甚至不是重新排列,而更像是将该指令移至其他所有内容的最顶部。[...] 这意味着在此之前不能有 JSP 块、JSP 指令、JSP 注释或任何东西。

For example, if your existing JSP page that gives you the error is:

例如,如果您现有的给您错误的 JSP 页面是:

<%-- Some JSP comment --%>
<% /* (OR) Some Java comment in JSP block */ %>
<%@ page import="com.abc.xyz.Helperjsp"%>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>

I misunderstood KarthikN's example and simply swapped the two lines. It did not work:

我误解了 KarthikN 的例子,只是交换了两行。它没有用:

<%-- Some JSP comment --%>
<% /* (OR) Some Java comment in JSP block */ %>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="com.abc.xyz.Helperjsp"%>

When the directive was placed above everything else, it worked:

当指令置于其他一切之上时,它起作用了:

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%-- Some JSP comment --%>
<% /* (OR) Some Java comment in JSP block */ %>
<%@ page import="com.abc.xyz.Helperjsp"%>

Although KarthikN's answer mentions this ("add the page encoding tag as the first declaration before any other declarations in the jsp"), the example provided doesn't make it clear.

尽管 KarthikN 的回答提到了这一点(“在 jsp 中的任何其他声明之前添加页面编码标记作为第一个声明”),但提供的示例并没有说清楚。