File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Problem with setProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with setProperty" Watch "Problem with setProperty" New topic

Problem with setProperty

Raghuraman Muthuswamy
Ranch Hand

Joined: Mar 18, 2003
Posts: 73
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";
speed = s;


JSP Code:

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);


Your help is very much appreciated.

Thanks in advance,

Joined: Jan 28, 2005
Posts: 6
your method "getSpeed" returns an int and you are storing error message in a string.that is tht reason you are not able to retrieve the message.
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
I wish to add this too. The setSpeed method receives an integer but the parameter recieved by the jsp page will be a string. So setSpeed will not execute.

It will take speed=0; always since it is initialised as zero.

One solution

set and getSpeed should recieve speed as String. Then do proper conversion and do the validation

Sarath Mohan
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858


We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Forum Bartender

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Problem with setProperty
It's not a secret anymore!