aspose file tools
The moose likes Servlets and the fly likes JSP and ValueBean..Tight Coupling.. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "JSP and ValueBean..Tight Coupling.." Watch "JSP and ValueBean..Tight Coupling.." New topic
Author

JSP and ValueBean..Tight Coupling..

Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
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

Joined: Mar 22, 2000
Posts: 12265
    
    1
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


Java Resources at www.wbrogden.com
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
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

Joined: Jan 30, 2000
Posts: 3219
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.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You need to move the setProperty code to display.jsp.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JSP and ValueBean..Tight Coupling..
 
Similar Threads
Problem with session
JBoss/config/Collections
java.lang.IllegalArgument Exception: No bean specified
Using redirect from backing bean and getting IllegalStateException error
Session Bean