我使用NetBeans与JavaServerFaces框架编写web应用程序。我的faces-config xml文件包含一个导航链接,我用它返回主页。主页包含幻灯片放映和下拉组合框,当从中选择时,将转到另一个页面。在这个页面上是一个链接,使我返回到主页。所有这些都很好,除了当我转到一个完全不同的页面并单击链接返回主页时,使用的组合框抛出错误,我得到可怕的
. lang。IllegalStateException: Component>>javax.faces.component.UIViewRoot@6685d2dd不是期望的类型。预期:>>> javax.faces.component.UIForm。也许你少了一个标签?
错误。此外,我所有的页面都包装在f:view标签中。有人能建议解决这个问题吗?谢谢你的帮助。My Home JSP Page:
<title>Quotes</title>
</head>
<body>
<h1>Quote Home Page</h1>
<h:form>
<h:commandLink action="#{QuoteMB.createSetup}" value="Add New Quote"/>
</h:form>
<h:form>
<h:commandLink action="#{Login.logout}" value="Log Out" />
</h:form>
</div>
<FORM ACTION="quoteview.jsp" METHOD="POST" >
<div style="text-align:center">
<h3>Please select the quote you want to display:</h3>
<BR>
<%
int count = 0;
int i = 0;
int reversecount = 0;
int originalcount = 0;
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/babylon", "root", "sequence");
Statement statement = connection.createStatement();
//import java.util.HashMap;
ResultSet resultset = statement.executeQuery("SELECT quotetext FROM quote");
java.util.HashMap <Integer,String> nametoValueMap = new java.util.HashMap <Integer,String>();
if (!resultset.next()) {
out.println("Sorry, no records found. ");
} else {
int j=0;
resultset.previous();
while(resultset.next()){
j++;
String qt=resultset.getString(1);
int len=0;
len=qt.indexOf("n");
if(len==-1)len=30;
if(len>30)len=30;
System.out.println("search length= "+len);
qt=qt.substring(0,len);
qt=qt.replace("'", "''");
System.out.println("final qt= "+qt);
nametoValueMap.put(j,qt);
System.out.println("Putting j "+j+" with "+qt);
}
count = j;
originalcount = count;
System.out.println("originalcount= "+originalcount);
out.print("<select name="id">");
while (count != 0) {
String text=nametoValueMap.get(reversecount);
System.out.println("Text = "+text+" reversecount= "+reversecount);
reversecount = originalcount - (count - 1);
//out.print("<option><column>" + reversecount + "</column></option>"); // where column1 is the column in the database table
out.print("<option><column>" + nametoValueMap.get(reversecount) + "</column></option>");
count--;
}
out.print("</select>");
}
resultset.close();
statement.close();
connection.close();
%>
<INPUT TYPE="SUBMIT" value="Go" class="input">
</div>
</FORM>
<br/>
<div style="text-align:center">
<a href="javascript:gotoshow()"><img src="Shakespeare2.jpg" name="slide" id="borderimg1" ></a>
</div>
<br/>
</html>
这是导航规则:<navigation-rule>
<navigation-case>
<from-outcome>welcome</from-outcome>
<to-view-id>/quote.jsp</to-view-id>
</navigation-case>
</navigation-rule>
这显示了当从主页上的组合框中进行选择时页面上显示的链接:引用视图
<h:commandLink action="#{QuoteMB.listSetup}" value="Show Quotes"/>
<br>
<h:commandLink value="Home" action="welcome" immediate="true" />
</h:form>
"
看来我的JSP文件需要放在pages文件夹和Web文件夹下。这对我来说很奇怪,但当我将文件复制到两个文件夹时,问题得到了解决。很抱歉占用大家的时间。谢谢你的帮助。