views:

52

answers:

2

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="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;
}

}

alt text

Where is the problem?

A: 

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.

Deepesh
Yes, it is placed in beans package
Csaryus
Your form action is wrong. It should be index.jsp. So once u submit the form it will display Message: 0.
Deepesh
Tried, nothing new..
Csaryus
well can u show me where u have stored your java class file
Deepesh
ok... I don't repeat myself.
Csaryus
A: 

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".

Csaryus