Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and ValueBean..Tight Coupling..  RSS feed

 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai All!
Here is my question.. I have one value bean and correspoding JSP page(Form) using ValueBean. Is there anyway that Valuebeans set Methods are automatically invoked when user submitted the form?
Or anyother alternative to accomplish this..
any Suggestions are appreciated
TIA
Rgds
Manohar
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to study the JSP API documents, downloadable from SUN. There really is no shortcut to mastering JSP.
The <jsp:setProperty tag will automatically look for and call setX methods corresponding to FORM properties named X
You must be careful that the variable and setX method names follow the naming rules.
Bill
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai William!
Thanks for ur reply.. But i tried it and it is not just working..
Here are two JSP pages.
JSP1: Here user will enter values,,,,,
<jsp:useBean id="login" scope="session" class="ValueBeans.Login" />
<jsp:setProperty name="login" property="*" />

<form action="display.jsp" method="get">
<Input type="text" name="UserID" >
<Input type="text" name="Password" >
<Input type="hidden" name="hidden" value="Set">
<Input type="submit" value="Login">
</form>
JSP2: Here i am trying to Display UserID but is not getting displayed.
<%@ page import="ValueBeans.*" %>
<jsp:useBean id="login" scope="session" class="ValueBeans.Login" />
<%
out.println("Hello world!");
out.println(login.getUserID());
%>
ValueBean: This is value bean
package ValueBeans;
public class Login
{
private String strUserId;
private String strPassword;
public void setUserID(String strUserId)
{
this.strUserId=strUserId;
}
public void setPassword(String strPassword)
{
this.strPassword=strPassword;
}
public String getPassword()
{
return strPassword;
}
public String getUserID()
{
return strUserId;
}
}

So..Pls tell me where i am going wrong?
TIA
Rgds
Manohar
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not following convention:
Try:
<Input type="text" name="userID" >
<Input type="text" name="password" >
I.e., lower case beginning letter of input element name.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to move the setProperty code to display.jsp.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!