在springboot中调用方法时未发现方法异常
method not found exception while invoking method in springboot
Feb 17, 2022 10:06:40 AM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: ritu.login.User@d570e4f.validate()
javax.faces.FacesException: #{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: ritu.login.User@d570e4f.validate()
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:110)
这是我的 login.xhtml 文件
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<body>
<h:form>
<p:panel header="Login">
<p:messages id="msgs" showDetail="true"/>
<h:outputText value="id" />
<h:inputText id="id" value="#{loginBean.id}"></h:inputText>
<h:message for="id"></h:message>
<br></br>
<br></br>
<h:outputText value="name" />
<h:inputText id="name" value="#{loginBean.name}"></h:inputText>
<h:message for="name"></h:message>
<p:commandButton action="#{loginBean.validate}" value="login" update="msgs" ></p:commandButton>
</p:panel>
<br></br>
<br></br>
</h:form>
</body>
</html>
这是我的class
package ritu.login;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
@ManagedBean(name = "loginBean")
@SessionScoped
public class User implements Serializable{
private static final long serialVersionUID = -7250065889869767422L;
@Id
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String validate(Long id, String name) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/any", "root", "jaygurudev1@");
PreparedStatement ps = con.prepareStatement("Select id,name from user where id=? and name=?");
ps.setLong(1, id);
ps.setString(2, name);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return "index.xhtml";
} else {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
"Incorrect Username and Passowrd", "Please enter correct username and Password"));
return "login.xhtml";
}
} catch (Exception e) {
System.out.println("in exception");
}
return "ok";
}
}
为什么会出现这个异常,这是想表达什么?我以前在 commandButton 中使用过 h 标签,但它不起作用
原因:javax.faces.el.MethodNotFoundException:javax.el.MethodNotFoundException:/index.xhtml @23,80 action="#{loginBean.validate}":找不到方法:ritu.login.User@d570e4f.validate()
在 javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
在 com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 29 更多
引起:javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": 找不到方法:ritu.login.User@d570e4f.validate()
在 com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109)
在 javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 30 多个
2022 年 2 月 17 日 10:06:40 上午 com.sun.faces.context.ExceptionHandlerImpl 日志
1100: JSF1073: javax.faces.FacesException 在 INVOKE_APPLICATION 5 的处理过程中被捕获:UIComponent-ClientId=, Message=#{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23 ,80 action="#{loginBean.validate}":找不到方法:ritu.login.User@d570e4f.validate()
2022 年 2 月 17 日 10:06:40 上午 com.sun.faces.context.ExceptionHandlerImpl 日志
您必须在 login.xhtml
中的 #{loginBean.validate}
附近传递参数。
变化:
<p:commandButton action="#{loginBean.validate}" value="login" update="msgs" ></p:commandButton>
收件人:
<p:commandButton action="#{loginBean.validate(loginBean.id, loginBean.name)}" value="login" update="msgs" ></p:commandButton>
Feb 17, 2022 10:06:40 AM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: ritu.login.User@d570e4f.validate()
javax.faces.FacesException: #{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: ritu.login.User@d570e4f.validate()
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:110)
这是我的 login.xhtml 文件
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<body>
<h:form>
<p:panel header="Login">
<p:messages id="msgs" showDetail="true"/>
<h:outputText value="id" />
<h:inputText id="id" value="#{loginBean.id}"></h:inputText>
<h:message for="id"></h:message>
<br></br>
<br></br>
<h:outputText value="name" />
<h:inputText id="name" value="#{loginBean.name}"></h:inputText>
<h:message for="name"></h:message>
<p:commandButton action="#{loginBean.validate}" value="login" update="msgs" ></p:commandButton>
</p:panel>
<br></br>
<br></br>
</h:form>
</body>
</html>
这是我的class
package ritu.login;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
@ManagedBean(name = "loginBean")
@SessionScoped
public class User implements Serializable{
private static final long serialVersionUID = -7250065889869767422L;
@Id
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String validate(Long id, String name) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/any", "root", "jaygurudev1@");
PreparedStatement ps = con.prepareStatement("Select id,name from user where id=? and name=?");
ps.setLong(1, id);
ps.setString(2, name);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return "index.xhtml";
} else {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
"Incorrect Username and Passowrd", "Please enter correct username and Password"));
return "login.xhtml";
}
} catch (Exception e) {
System.out.println("in exception");
}
return "ok";
}
}
为什么会出现这个异常,这是想表达什么?我以前在 commandButton 中使用过 h 标签,但它不起作用
原因:javax.faces.el.MethodNotFoundException:javax.el.MethodNotFoundException:/index.xhtml @23,80 action="#{loginBean.validate}":找不到方法:ritu.login.User@d570e4f.validate() 在 javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91) 在 com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) ... 29 更多 引起:javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": 找不到方法:ritu.login.User@d570e4f.validate() 在 com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109) 在 javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ... 30 多个
2022 年 2 月 17 日 10:06:40 上午 com.sun.faces.context.ExceptionHandlerImpl 日志 1100: JSF1073: javax.faces.FacesException 在 INVOKE_APPLICATION 5 的处理过程中被捕获:UIComponent-ClientId=, Message=#{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23 ,80 action="#{loginBean.validate}":找不到方法:ritu.login.User@d570e4f.validate() 2022 年 2 月 17 日 10:06:40 上午 com.sun.faces.context.ExceptionHandlerImpl 日志
您必须在 login.xhtml
中的 #{loginBean.validate}
附近传递参数。
变化:
<p:commandButton action="#{loginBean.validate}" value="login" update="msgs" ></p:commandButton>
收件人:
<p:commandButton action="#{loginBean.validate(loginBean.id, loginBean.name)}" value="login" update="msgs" ></p:commandButton>