Active TopicsActive Topics  Display List of Forum MembersMemberlist  CalendarCalendar  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
 One Stop GATE ForumGATE Technical DiscussionsGATE CS
Message Icon Topic: Interview questions ........... Post Reply Post New Topic
Author Message
Priya
Groupie
Groupie


Joined: 04Jan2007
Online Status: Offline
Posts: 82
Quote Priya Replybullet Topic: Interview questions ...........
    Posted: 15Feb2007 at 10:00am



How do I instantiate a bean whose constructor accepts parameters using the useBean tag?




Answer

    Consider the following bean: package bar;
public class FooBean {
public FooBean(SomeObj arg) {
...
}
//getters and setters here
}
The only way you can instantiate this bean within your JSP page is to use a scriptlet. For example, the following snippet creates the bean with session scope:
< % SomeObj x = new SomeObj(...);
bar.FooBean foobar = new FooBean(x);
session.putValue("foobar",foobar);
%> You can now access this bean within any other page that is part of the same session as: &l;%
bar.FooBean foobar = session.getValue("foobar");
%>
To give the bean "application scope", you will have to place it within the ServletContext as:
< %
application.setAttribute("foobar",foobar);
%>
To give the bean "request scope", you will have to place it within the request object as:
< %
request.setAttribute("foobar",foobar);
%>
If you do not place the bean within the request, session or application scope, the bean can be accessed only within the current JSP page (page scope). Once the bean is
instantiated, it can be accessed in the usual way:
jsp:getProperty name="foobar" property="someProperty"/ jsp:setProperty
name="foobar" property="someProperty" value="someValue"/
For More Sample Papers Visit:   
http://onestopgate.com/gate-preparation/



Post Resume: Click here to Upload your Resume & Apply for Jobs

IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

GET LATEST FRESHERS JOBS IN YOUR MAIL





This page was generated in 0.234 seconds.
Vyom is an ISO 9001:2000 Certified Organization

© Vyom Technosoft Pvt. Ltd. All Rights Reserved.

Job Interview Questions | Girls Magazine | DLL, OCX File Errors | Freshers Jobs | Placement Papers | More Papers