File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlet , bean , jsp  Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet , bean , jsp  Communication" Watch "servlet , bean , jsp  Communication" New topic

servlet , bean , jsp Communication

Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
Cld any1 tell me the way to set the property of a bean from a servlet, like setproperty inside JSP..
i want to set the value of a bean from a servlet and need to access this bean value from jsp..
is it a right practise to create a staitic instance of bean and using this instance in servlet for setting the bean property and for getting the bean value from jsp ??

SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Rajni Kumar

Joined: Mar 05, 2003
Posts: 8
create one javabean which should have set and get methods.
class TestBean{
int id ;
public void setId(int id){ =id;
public int getId(){
in servlet, create instance of that bean.
TestBean tb = new TestBean();
td.setId(3); // i am setting id as 3 in TestBean.
//then forward this servlet to JSP.
in JSP,
after defining page attributes...
don't forget to import ur bean package.
TestBean tb = (TestBean) request.getAttribute("TestBean");
int id = tb.getId();
out.println("id is"+id); // it will print 3 in ur jsp page.
all the best.
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
thanx cuttie,
this is wat i was looking for..thanx one again for ur instant reply..
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
java cute,
Please change your name to be compliant with JavaRanch's naming policy. It should not be obviously fictitious.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: servlet , bean , jsp Communication
It's not a secret anymore!