开发者

Problems with <jsp:setProperty .../>

I wrote next jsp:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
    <h1>Monster Calculator</h1>
    <FORM METHOD=开发者_如何学Go"POST" ACTION="Controller">
        N1: <input type ="text" name="nr1" value="0">
        op: <input type ="text" name="op" value="+">
        N2: <input type ="text" name="nr2" value="0">
        <INPUT class ="button" TYPE="submit" NAME="actiune" VALUE="Calculate"/>
    </FORM>
    <jsp:useBean id="binaryOperation" class="beans.BinaryOperation" scope="session"/>
    <jsp:setProperty name="binaryOperation" property="*"/>
    Message: <jsp:getProperty name="binaryOperation" property="nr1"/>

</body>

Theproblem is that I expect that next line:

Message: <jsp:getProperty name="binaryOperation" property="nr1"/>

to display "Message: 0" at runtime.

This is the bean:

public class BinaryOperation {

private String nr1 = "";
private String op = "";
private String nr2 = "";

public void setNr1(String nr1) {
    this.nr1 = nr1;
}

public void setOp(String op) {
    this.op = op;
}

public void setNr2(String nr2) {
    this.nr2 = nr2;
}

public String getNr1() {
    return nr1;
}

public String getOp() {
    return op;
}

public String getNr2() {
    return nr2;
}

}

Problems with <jsp:setProperty .../>

Where is the problem?


Is your BinaryOperation class defined in a package?
This line of code indicates that your class is in package "beans":

<jsp:useBean id="binaryOperation" class="beans.BinaryOperation" scope="session"/>

Please do check if your class belongs to "beans" package or not.

Thanks.


I've did one more jsp file between index.jsp and Servlet:

<jsp:useBean id="binOp" class="beans.BinaryOperation" scope="session"/>
<jsp:setProperty name="binOp" property="*"/>

This did the "magic".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜