jsf错误急
HTTP Status 500 -
--------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: #{user.show}: javax.faces.el.MethodNotFoundException: show: java.util.TreeMap.show()
javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
root cause
javax.faces.FacesException: #{user.show}: javax.faces.el.MethodNotFoundException: show: java.util.TreeMap.show()
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIData.broadcast(UIData.java:657)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
弄表界面
<f:view>
<h:form>
<center>
<h:dataTable title="用户信息" bgcolor="red" var="user" value="#{user.all}" border="1" width="80%">
<h:column>
<f:facet name="header">
<h:outputText value="编号">
</h:outputText>
</f:facet>
<h:outputText value="#{user.id}">
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="用户名">
</h:outputText>
</f:facet>
<h:outputText value="#{user.name}">
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="密码">
</h:outputText>
</f:facet>
<h:outputText value="#{user.pwd}">
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="修改"></h:outputText>
</f:facet>
<h:commandLink action="#{user.show}">
<f:param value="#{user.id}" name="ID">
</f:param>
<h:outputText value="修改">
</h:outputText>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="删除"></h:outputText>
</f:facet>
<h:commandLink action="#{user.Delete}">
<f:param value="#{user.id}" name="ID">
</f:param>
<h:outputText value="删除">
</h:outputText>
</h:commandLink>
</h:column>
</h:dataTable>
<h:commandButton value="添加" action="add"/>
</center>
</h:form>
</f:view>
受托管的bean
/*
* user.java
*
* Created on 2007年10月10日, 上午10:12
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package myjsf;
import java.sql.*;
import java.util.*;
import javax.faces.context.*;
import javax.faces.model.*;
import javax.servlet.jsp.jstl.sql.*;
import javax.faces.event.ActionEvent;
/**
*
* @author jiangxu
*/
public class user {
public String AddUser()
{
if(name.equals(""))
{
setMessages("请填写用户名!");
strResult="AddFalse";
}
if(pwd.equals(""))
{
setMessages("请填写密码!");
strResult="AddFalse";
}
if(!name.equals("")&&!pwd.equals(""))
{
String sql="insert into xt_user (name,pwd) values ("+"'"+name+"',"+"'"+pwd+"')";
sqlHelper spr=new sqlHelper();
try
{
spr.execute(sql);
strResult="Addtrue";
}
catch(Exception ex){}
}
return strResult;
}
public Result getAll() throws SQLException
{
try{
String sql = "select * from xt_user";
sqlHelper spr = new sqlHelper();
ResultSet rs = spr.executeQuery(sql);
return ResultSupport.toResult(rs);
}
catch (SQLException ex) {
}
return null;
}
public String Delete()
{
try {
FacesContext ctx = FacesContext.getCurrentInstance();
String ID = (String)ctx.getExternalContext().getRequestParameterMap().get("ID");
String sql = "delete from xt_user where ID="+ID;
sqlHelper spr = new sqlHelper();
spr.executeUpdate(sql);
}
catch (SQLException ex) {
}
return "list";
}
public String show()
{
FacesContext ctx = FacesContext.getCurrentInstance();
String ID = (String)ctx.getExternalContext().getRequestParameterMap().get("ID");
String sql = "select * from xt_user where ID="+ID;
sqlHelper spr = new sqlHelper();
try {
ResultSet rs = spr.executeQuery(sql);
if(rs.next())
{
this.setId(rs.getString(1));
this.setName(rs.getString(2));
this.setPwd(rs.getString(3));
System.out.println(this.getId());
}
}
catch (SQLException ex) {
}
return "update";
}
public String validate()
{
if(name.equals("")||pwd.equals(""))
{
setMessages("用户名和密码不能为空!");
strResult= "false";
}
if(!name.equals("")&&!pwd.equals(""))
{
String sql="select * from xt_user where name="+"'"+name+"'"+" and pwd='"+pwd+"'";
sqlHelper spr=new sqlHelper();
try
{
ResultSet rs=spr.executeQuery(sql);
if(rs.next())
strResult= "true";
else
{
setMessages("用户名或密码错误!");
strResult= "false";
}
}
catch(Exception ex)
{}
}
return strResult;
}
}
[解决办法]
<h:dataTable title="用户信息" bgcolor="red" var="user" value="#{user.all}" border="1" width="80%" >
改成:
<h:dataTable title="用户信息" bgcolor="red" var="u" value="#{user.all}" border="1" width="80%" >
下面的列也相应的改成u,
但是action中的不要改,还用user
错误原因是由于你的backbean和你自己写的var="user" 重名了,系统不能区分
解决了请结贴,谢谢
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html