| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3051 人关注过本帖
标题:JSF的javax.faces.el.MethodNotFoundException
取消只看楼主 加入收藏
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
 问题点数:0 回复次数:5 
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>
为什么总提示找不到那几个方法?跟方法的返回类型有关系吗?谢谢!
搜索更多相关主题的帖子: JSF faces quot javax uri 
2008-01-17 09:57
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
我试过另外一个例子,就是验证用户名和密码的,方法还是我自己定义的,而且调用也像这个例子一样,可以运行,就不知道为什么这个不行...

I'm here, as always...
2008-01-17 11:44
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
顶个

I'm here, as always...
2008-01-18 09:45
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
沉第二页了

I'm here, as always...
2008-01-21 10:38
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
晕死啊~~~~~~~~~~~~
原来#{cal.add}这里,add和}之间不能有空格啊!!!
试了好久终于弄好了!!!
这个印象深刻了!!!

I'm here, as always...
2008-01-21 10:42
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
我也用的Eclipse3.2,还行吧,就是没有找到本好教材,只有一个在线教程,只有结合点以前做的东西自己编,呵呵,用习惯了也不错感觉

I'm here, as always...
2008-01-23 09:26
快速回复:JSF的javax.faces.el.MethodNotFoundException
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.088581 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved