gpt4 book ai didi

jsf - 使用JSF/Facelets处理带有后备bean问题的页面时出错

转载 作者:行者123 更新时间:2023-12-03 07:43:54 26 4
gpt4 key购买 nike

this solution之后,我制作了一个错误页面,如下所示:

在faces-config.xml中

<error-page>
<error-code>500</error-code>
<location>/errore500.xhtml</location>
</error-page>

....

<managed-bean>
<managed-bean-name>errore</managed-bean-name>
<managed-bean-class>it.jlp.prometheus.modello.Errore</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

...页面errore500.xhtml ...
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="author" content="JLP" />
<link rel="stylesheet" href="css/stile.css" type="text/css" />
<link rel="icon" href="icons/favicon.png" type="image/png" />
<title>Prometheus - Error 500</title>
</head>

<body>
<h:form>

....

<br/><h:inputTextarea style="width: 100%;" rows="20" readonly="true"
value="#{errore.stackTrace}" />

....

...以及类(class)Errore
public class Errore implements Serializable {

private Log logger = LogFactory.getLog(Errore.class);

public String getStackTrace() {
FacesContext context = FacesContext.getCurrentInstance();
Map requestMap = context.getExternalContext().getRequestMap();
Throwable ex = (Throwable) requestMap.get("javax.servlet.error.exception");
StringWriter writer = new StringWriter();
PrintWriter pw = new PrintWriter(writer);
fillStackTrace(ex, pw);
logger.info("****** getStackTrace executed ");
return writer.toString();
}

private void fillStackTrace(Throwable ex, PrintWriter pw) {
if (null == ex) {
return;
}
ex.printStackTrace(pw);
if (ex instanceof ServletException) {
Throwable cause = ((ServletException) ex).getRootCause();
if (null != cause) {
pw.println("Root Cause:");
fillStackTrace(cause, pw);
}
} else {
Throwable cause = ex.getCause();

if (null != cause) {
pw.println("Cause:");
fillStackTrace(cause, pw);
}
}
}

有了这段代码,当我在应用程序的另一部分中故意引起某种欺骗(ClassCastException)时,它将我重定向到此页面,但是,通过将调试打印日志放入支持bean类中,我看到它从未实例化,因此文本该区域不会有人居住。
为什么从未实例化后备bean?

最佳答案

那个地点

<location>/errore500.xhtml</location>

必须与 FacesServlet的URL模式匹配。

因此,例如将其映射到
<url-pattern>*.jsf</url-pattern>

那么您需要将位置设置为
<location>/errore500.jsf</location>

关于jsf - 使用JSF/Facelets处理带有后备bean问题的页面时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6127594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com