JSF的javax.faces.el.MethodNotFoundException
初学遇到奇怪的问题,怎么改都没用,求教大家了!calculator.jsp页面要求输入两个数,然后选择一个方法,然后就跳转到result.jsp页面显示结果。但是点击方法后总会显示这个异常。calculator.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java. prefix="f" %>
<%@taglib uri="http://java. prefix="h" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Calculate Page</title>
</head>
<body>
<h1>JSF Calculator Example</h1><br/>
<f:view>
<h:form>
<table>
<tr>
<td><b>First Number:</b></td>
<td><h:inputText value="#{cal.firstNum }" /></td>
</tr>
<tr>
<td><b>Second Number:</b></td>
<td><h:inputText value="#{cal.secondNum }" /></td>
</tr>
</table>
<h:commandButton value="+" action="#{cal.add }" />
<h:commandButton value="-" action="#{cal.minus }" />
<h:commandButton value="*" action="#{cal.multiply }" />
<h:commandButton value="/" action="#{cal.divide }" />
</h:form>
<h:outputLink value="index.faces" ><h:outputText value="abc" /></h:outputLink>
</f:view>
</body>
</html>
result.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java. prefix="f" %>
<%@taglib uri="http://java. prefix="h" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Calculate Result Page</title>
</head>
<body>
<h1>Calculator Result Page</h1><br/>
<f:view>
First Number:<h:outputText value="#{cal.firstNum }" /><br/>
Second Number:<h:outputText value="#{cal.secondNum }" /><br/>
Result:<h:outputText value="#{cal.result }" />
</f:view>
</body>
</html>
然后是两个类:
Calculator.java:
package src;
public class Calculator {
public double add (double a, double b) {
return a + b;
}
public double minus (double a, double b) {
return a - b;
}
public double multiply (double a, double b) {
return a * b;
}
public double divide(double a, double b) {
if(b != 0) {
return a / b;
} else {
return Double.MAX_VALUE;
}
}
}
CalculatorController.java:
package src;
public class CalculatorController {
private double firstNum = 0;
private double secondNum = 0;
private double result = 0;
private Calculator calculator = new Calculator();
public String add() {
result = calculator.add(firstNum, secondNum);
return "complete";
}
public String minus() {
result = calculator.minus(firstNum, secondNum);
return "complete";
}
public String multiply() {
result = calculator.multiply(firstNum, secondNum);
return "complete";
}
public String divide() {
result = calculator.divide(firstNum, secondNum);
return "complete";
}
public Calculator getCalculator() {
return calculator;
}
public void setCalculator(Calculator calculator) {
this.calculator = calculator;
}
public double getFirstNum() {
return firstNum;
}
public void setFirstNum(double firstNum) {
this.firstNum = firstNum;
}
public double getResult() {
return result;
}
public void setResult(double result) {
this.result = result;
}
public double getSecondNum() {
return secondNum;
}
public void setSecondNum(double secondNum) {
this.secondNum = secondNum;
}
}
然后是配置文件faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN" "http://java.
<faces-config>
<navigation-rule>
<navigation-case>
<from-outcome>complete</from-outcome>
<to-view-id>/result.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>cal</managed-bean-name>
<managed-bean-class>src.CalculatorController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
</faces-config>
为什么总提示找不到那几个方法?跟方法的返回类型有关系吗?谢谢!