我在执行jsf应用程序时遇到了一些异常。这是我的xhtml代码。在执行xhtml时出现非法状态异常
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view>
<h:head><title>Index</title></h:head>
<body>
<h:form>
<h:outputText value="#{login.userName}"></h:outputText><br/>
<h:inputText id="userId" value="#{emp.userId}"></h:inputText>
<h:commandButton action="#{emp.check}" value="check"/>
</h:form>
</body>
</f:view>
</html>
这里登录是一个托管bean。我从bean中获取用户名并尝试显示它。而emp是我在此使用的另一个bean。 当我运行这个服务器时,我得到以下异常。
Stacktrace:] with root cause
java.lang.IllegalStateException: Component [email protected] not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?
at com.sun.faces.taglib.html_basic.OutputTextTag.setProperties(OutputTextTag.java:126)
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:686)
你检查'userName'价值,因为根据你的堆栈跟踪它的返回'null'。你可以发布'登录'豆代码! – dShringi 2013-02-21 05:41:12
我从会话中获取用户名值。它显示当我运行上面的xhtml。但是,在我输入文本字段中的id并提交后,即时获取org.apache.jasper.JasperException:javax.servlet.ServletException:javax.servlet.jsp.JspException:java.lang.IllegalStateException:Component javax.faces.component.UIViewRoot @ 1b70f9e不是预期的类型。预期:javax.faces.component.UIOutput。也许你错过了一个标签? – cherry 2013-02-21 06:00:27
Facelets(XHTML)文件以某种方式被解释为JSP文件。这表明一个严重混乱的JSF配置。显示你的'web.xml'并列出'/ WEB-INF/lib'中的JAR,以便我们指出原因。目前接受的可汗答案不可能是“正确的”答案,请不要随便接受答案以便接受答案。 – BalusC 2013-02-21 11:59:58