Hi all,
I am trying use a bean which has a setProperty. In the setProperty i have a If loop. But when i run the
JSP page the condition is not satisfying. I have a text box to enter Speed. That page is posted to a JSP page where i receive the text box value. If the value is negative i have to execute the bean if condition. But its not working. will give you the code. Pls correct the error and explain me what i did wrong.
Bean Code:
package ecom;
public class SC
{
private int speed;
private
String sp;
public int getSpeed()
{
return speed;
}
public void setSpeed(int s)
{
if (speed<0)
{
sp = "Speed Can't be Negative";
}
else
{
speed = s;
}
}
}
JSP Code:
<body>
<%
String var = request.getParameter("speed");
int var1 = Integer.parseInt(var);
%>
<h1>Speed of the Car is <%= var%></h1><br>
<jsp:useBean id="speed" class="ecom.SC" />
<jsp:setProperty name="speed" property="speed" value = '<%= var1%>' />
<jsp:getProperty name="speed" property="speed"/>
<%
System.out.println("Speed = "+var1);
%>
</body>
Your help is very much appreciated.
Thanks in advance,
Raghu