Hello, i have to do a project that presents a form with 3
text fields like this
[img]http://i47.tinypic.com/1jsw44.jpg[/img]
type 2 numbers and then the symbol(+,/,*,-) and do the
appropriate action.
I am using Tomcat 6.0.
I've done so far:

#simple.html

<html>
<body>
<form method="post" action="simple.jsp">
Number_1<br> <input type="text" name="value1"><p>
Number_2<br> <input type="text" name="value2"><p>
Symbol<br> <input type="text" name="value3"><br>
<input type="submit" value="Submit">
</body>
</html>

#simple.jsp

<jsp:useBean id="SimpleBean" class="test.SimpleBean" scope="page">
</jsp:useBean>
<jsp:setProperty name="SimpleBean" property="*"/>
<% SimpleBean.add(); %>

<html>
<body>


Sum = <jsp:getProperty name="SimpleBean" property="result"/> <br>

Symbol = <jsp:getProperty name="SimpleBean" property="symbol"/>


</body>
</html>

#SimpleBean.java

package test;

public class SimpleBean {
	
	private int value1;
	private int value2;
	private int result;
	private String value3;
	private String symbol;
	

	public void setValue1(int x){
		value1 = x;
	}
	
	public void setValue2(int x){
		value2 = x;
	}
	
	public void setValue3(String x){
		value3 = x;
	}
	
	public int getResult(){
		return result;
	}
	
	public String getSymbol(){
		return symbol;
	}
	
	public void add(){
		result = value1+value2;
	}

}

so far i didn't tried to check what the symbol is because i put
the program to print it and prints null.
Look: [img]http://i48.tinypic.com/otj5s1.jpg[/img]

i don't know what i'm doing wrong. :(
Please any help would be appreciated. :)

Recommended Answers

All 4 Replies

Obvious, you never pass any values to SimpleBean for processing.

Obvious, you never pass any values to SimpleBean for processing.

if you see the image

http://i48.tinypic.com/otj5s1.jpg

it passes the 2 numbers and calculate the sum and prints it,
but the string variable returns null.

remove private String Value3 and change setValue3 with code like this

public void setSymbol(String x){
    symbol = x;
}

Then rename

Symbol<br> <input type="text" name="value3"><br>

with this

Symbol<br> <input type="text" name="symbol"><br>

i solved it like a week ago, but
thnx for the interest.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.