Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple html form, jsp and bean - but jsp returning null values instead

Status
Not open for further replies.

GLCHY

Programmer
Mar 16, 2002
3
US
Hi,

i have a very simple html form, jsp and bean. In the form i input values for name, email and age. The jsp simply has to return and display those values. However im getting null values and i cant figure out why (either im setting the property incorrectly or getting it incorrectly).

GetName2.html
=============
<jsp:useBean id=&quot;user&quot; class=&quot;Test.UserData&quot;
scope=&quot;session&quot; />
<jsp:setProperty name=&quot;user&quot; property=&quot;*&quot; />

<html>
<body>
<form method=post action=&quot;GetName2.jsp&quot;>
Name?<input type=text name=username><br>
email?<input type=text name=email><br>
age?<input type=text name=age><br>
<input type=submit>
</form>
</body>
</html>

GetName2.jsp
============
<jsp:useBean id=&quot;user&quot; class=&quot;Test.UserData&quot;
scope=&quot;session&quot; />

<html>
<body>
Name:<%= user.getUsername() %> <br>
Email:<%= user.getEmail() %><br>
Age: <%= user.getAge() %> <br>
</body>
</html>

UserData.java
=============
package Test;

public class UserData {
String username;
String email;
int age;

public void setUsername(String value)
{
username = value;
}

public void setEmail(String value)
{
email = value;
}

public void setAge(int value)
{

age = value;
}

public String getUsername() { return username; }

public String getEmail() { return email; }

public int getAge() { return age; }
}

Result(============================================================
Name:null
Email:null
Age: 0

Any idea? Im using Apache Tomcat 4 and JSDK 1.3.1

Thanks,
GC.
 
Why don't u try removing

<jsp:useBean id=&quot;user&quot; class=&quot;Test.UserData&quot;
scope=&quot;session&quot; />
<jsp:setProperty name=&quot;user&quot; property=&quot;*&quot; />

from GetName2.html as it is not necessaru in a simple html page

and then add
<jsp:setProperty name=&quot;user&quot; property=&quot;*&quot; />
below
<jsp:useBean id=&quot;user&quot; class=&quot;Test.UserData&quot;
scope=&quot;session&quot; />
in GetName2.jsp

I hope it works like this...I didn;t test it though

Dan. W. :)-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top