使用参数 JSP 调用函数



编辑:交换${h.helloWorldName('Audren')}${h.getHelloWorldName('Audren')}

我有一个测试类:

public class classtest {
    private String helloWorld;
    private String helloWorldName;
    public String getHelloWorld(){
        return "Hello world!";
    }
    public void setHelloWorld(String s) {
        helloWorld = s;
    }
    public String getHelloWorldName(String s) {
        return getHelloWorld() + s;
    }

在我的jsp中,我想打印我的方法getHelloWorldName的结果。这是我到目前为止尝试过的:

<jsp:useBean id="h" class="com.test.classtest" scope="page" />
<c:out value="${h.helloWorldName('Audren'}" />

但没有成功。我错过了什么吗?我也试过#{h.helloWorldName('Audren'}

你只是缺少一个括号(并删除"')。正确的语法:

"${h.helloWorldName(Audren)}"

最新更新