Hi,
First things first,
It is important to realize that all JSP's get converted into servlets, so
anything that a servlet can do, such as session tracking, can be acheived by
JSP's.
In JSP's we can get hold of an implicit session object like so
<% String thisSession = session.getId(); %>
There are a number of implicit objects available to JSP's and a quick browse of
the Syntax Card (http://java.sun.com/products/jsp/syntax.html) will make this
clear.
When you click the button you want to call a method in the bean?
Ok, first so that we have a common frame of reference I'll asume that the top of
your JSP looks like this:
<%@ page import="com.your_Co.beans.NameHandler" %>
<jsp:useBean id="mybean" scope="page" class="com.your_Co.beans.NameHandler"
type="com.your_Co.beans.NameHandler" >
<jsp:setProperty name="mybean" property="username" />
</jsp:useBean>
obviously this is making sure that you have imported the bean into you page
invokes a bean called mybean, its scope is just for this page, the beans class is
NameHandler.class and it is in the package com.your_Co.beans (make sure that this
package is in the classpath for your servlet/JSP engine! )
the NameHandler.java file it'self looks like
/* NameHandler.java bean */
package com.your_Co.beans;
public class NameHandler {
private String thename = "World"; //private resource
public void setUsername( String name ) {
thename = name;
}
public String getUsername() {
return thename;
}
}
Now then, you notice the line
<jsp:setProperty name="mybean" property="username" />
well this invokes the method setUsername() in the bean mybean. Now the nice thing
about this is that if this page has a property called "username" it's value will
be set in the bean's "thename" private variable.
this property can be sent to the page from a form by having a textfield in the
form whose name is "username" and the action of the form is pointing at your JSP.
To make sure that all propeties are that are valid for this bean when it is
instantiated you can use
<jsp:setProperty name="mybean" property="*" />
Note that for this to work automatically the setxxxx() method of the bean must be
the same as the property name ie if the property name is "accountdata" the
setxxxx() method must be called setAccountdata(String data)
conversley a
<jsp:getProperty name="mybean" property="username" />
will invoke the getUsername() function of the bean mybean.
To call any other methods of your bean use
<% mybean.Anymethod_that_we_want() %>
anywhere that is appropriate in you JSP
Hope this helps
Karl
Masaoud wrote:
> Hi,
>
> I have a JSP which uses a bean. There is a Form that is present in the
> JSP. This Form contains some TextFields and a Button.
>
> When I click this Button I want to do the following :
> 1. Call one of the methods in my Bean.
> 2. Get all the data that was inputed in the text fields into the
> Beans member variables.
>
> How can I do the above without using JavaScript.
>
> One more doubt I had, is that is there any Session Tracking
> Functionality provided with JSP's.
>
> Thanx,
> Masaoud.
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html