H
harryos
hi,
while going through some jsp examples ,I came across one that sets
javabean properties using user input values .
userinput.jsp
------------------
....
<body>
<h2>Entry Form</h2>
<form name="InputForm" method="post" action="setBean.jsp">
Enter your Name:
<input type="text" name="username" value="" />
Enter your Email:
<input type="text" name="email" value="" />
<input type="submit" value="OK" />
</form>
....
setBean.jsp
--------------
....
<jsp:useBean id="userB" class="org.mypackage.user.UserBean" >
<jsp:setProperty name="userB" property="*"/>
</jsp:useBean>
<body>
<h2>Posted Data</h2>
<strong> UserName </strong>
<cut value="${userB.username}" /><br>
<strong> Email </strong>
<cut value="${userB.email}" /><br>
....
where the UserBean.java is
public class UserBean implements java.io.Serializable{
String username;
String email;
public UserBean( ){}
public void setUsername(String _username){
if(_username != null && _username.length( ) > 0)
username = _username;
else
username = "Unknown";
}
public String getUsername( ){
if(username != null)
return username;
else
return "Unknown";
}
....
}
Why do UserBean need to implement Serializable interface? I tried it
without implementing Serializable and the fields are set correctly
according to the user input .Isn't this implements clause unnecessary?
thanks
harry
while going through some jsp examples ,I came across one that sets
javabean properties using user input values .
userinput.jsp
------------------
....
<body>
<h2>Entry Form</h2>
<form name="InputForm" method="post" action="setBean.jsp">
Enter your Name:
<input type="text" name="username" value="" />
Enter your Email:
<input type="text" name="email" value="" />
<input type="submit" value="OK" />
</form>
....
setBean.jsp
--------------
....
<jsp:useBean id="userB" class="org.mypackage.user.UserBean" >
<jsp:setProperty name="userB" property="*"/>
</jsp:useBean>
<body>
<h2>Posted Data</h2>
<strong> UserName </strong>
<cut value="${userB.username}" /><br>
<strong> Email </strong>
<cut value="${userB.email}" /><br>
....
where the UserBean.java is
public class UserBean implements java.io.Serializable{
String username;
String email;
public UserBean( ){}
public void setUsername(String _username){
if(_username != null && _username.length( ) > 0)
username = _username;
else
username = "Unknown";
}
public String getUsername( ){
if(username != null)
return username;
else
return "Unknown";
}
....
}
Why do UserBean need to implement Serializable interface? I tried it
without implementing Serializable and the fields are set correctly
according to the user input .Isn't this implements clause unnecessary?
thanks
harry