| | |
how to call javabean from jsp
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2007
Posts: 83
Reputation:
Solved Threads: 2
Push, can you provide a little clearer post with more specific details about what you are trying to do and what the problem is...
typically in JSP you would use the useBean tag to indicate what Bean you want to use...
There are paramters to indicate the class or type of bean to use and scope of the bean and name or id of the bean....
if the bean doesn't already exist in the scope you have indicated, it will be created if you have provided the class parameter, if you only provided the type parameter, it will not create a new one, but only use the existing one, if it exists... so type is useful only if you know the bean already exists in the scope... and you don't want a new one created.... default scope, I believe, is page based, so it will not persist unless you make it a larger scope...
So you call the <JSP:useBean ...> you provide a name/id for the bean and a class for the bean... in the useBean tage you use id="XXX" to give the bean a name and then when you set or get values later you use name="XXX" to indicate the name you gave the bean in its id="XXX" earlier.... this sems strange... when you create the bean, you give it an "id" this id becomes the "name" you used in later tags to refer to the bean... why didn't they jsut make all tags call it name="XXX" or id="XXX" rather thanmixing them.... who knows... in any case be careful of that point....
Scope can be page, request, session or application
the bean file should be in a JAR file and should be in /WEB-INF/lib or be in a folder structure that matches the package structure the folder structure must be sub-folders of /WEB-INF/classes
i.e. /WEB-INF/classes/com/rgtaylor/java/web/beans
or
/WEB-INF/lib/rgtaylorBeans.jar
If your Web Hosting company or SysAdmin doesn't allow you to use those locations, you can not do anything with it really... your only option then is to include the code directly inthe JSP files, which is not a good idea...
if you are asking how to place the files in some other location... unless you hack the server source, you can't... it is coded, for security reasons to require a /WEB-INF/ location... things under this folder can not be directly accessed or referenced from outside your webapp... So I place my main pages under "webapps/myapp", for example, but then all the included stuff, is placed under "webapps/myapps/WEB-INF/"...
Peace,
typically in JSP you would use the useBean tag to indicate what Bean you want to use...
There are paramters to indicate the class or type of bean to use and scope of the bean and name or id of the bean....
if the bean doesn't already exist in the scope you have indicated, it will be created if you have provided the class parameter, if you only provided the type parameter, it will not create a new one, but only use the existing one, if it exists... so type is useful only if you know the bean already exists in the scope... and you don't want a new one created.... default scope, I believe, is page based, so it will not persist unless you make it a larger scope...
So you call the <JSP:useBean ...> you provide a name/id for the bean and a class for the bean... in the useBean tage you use id="XXX" to give the bean a name and then when you set or get values later you use name="XXX" to indicate the name you gave the bean in its id="XXX" earlier.... this sems strange... when you create the bean, you give it an "id" this id becomes the "name" you used in later tags to refer to the bean... why didn't they jsut make all tags call it name="XXX" or id="XXX" rather thanmixing them.... who knows... in any case be careful of that point....
Scope can be page, request, session or application
the bean file should be in a JAR file and should be in /WEB-INF/lib or be in a folder structure that matches the package structure the folder structure must be sub-folders of /WEB-INF/classes
i.e. /WEB-INF/classes/com/rgtaylor/java/web/beans
or
/WEB-INF/lib/rgtaylorBeans.jar
If your Web Hosting company or SysAdmin doesn't allow you to use those locations, you can not do anything with it really... your only option then is to include the code directly inthe JSP files, which is not a good idea...
if you are asking how to place the files in some other location... unless you hack the server source, you can't... it is coded, for security reasons to require a /WEB-INF/ location... things under this folder can not be directly accessed or referenced from outside your webapp... So I place my main pages under "webapps/myapp", for example, but then all the included stuff, is placed under "webapps/myapps/WEB-INF/"...
Peace,
•
•
Join Date: Apr 2007
Posts: 33
Reputation:
Solved Threads: 0
thank u sir, 4 u r timely replay.............
•
•
•
•
Push, can you provide a little clearer post with more specific details about what you are trying to do and what the problem is...
typically in JSP you would use the useBean tag to indicate what Bean you want to use...
There are paramters to indicate the class or type of bean to use and scope of the bean and name or id of the bean....
if the bean doesn't already exist in the scope you have indicated, it will be created if you have provided the class parameter, if you only provided the type parameter, it will not create a new one, but only use the existing one, if it exists... so type is useful only if you know the bean already exists in the scope... and you don't want a new one created.... default scope, I believe, is page based, so it will not persist unless you make it a larger scope...
So you call the <JSP:useBean ...> you provide a name/id for the bean and a class for the bean... in the useBean tage you use id="XXX" to give the bean a name and then when you set or get values later you use name="XXX" to indicate the name you gave the bean in its id="XXX" earlier.... this sems strange... when you create the bean, you give it an "id" this id becomes the "name" you used in later tags to refer to the bean... why didn't they jsut make all tags call it name="XXX" or id="XXX" rather thanmixing them.... who knows... in any case be careful of that point....
Scope can be page, request, session or application
the bean file should be in a JAR file and should be in /WEB-INF/lib or be in a folder structure that matches the package structure the folder structure must be sub-folders of /WEB-INF/classes
i.e. /WEB-INF/classes/com/rgtaylor/java/web/beans
or
/WEB-INF/lib/rgtaylorBeans.jar
If your Web Hosting company or SysAdmin doesn't allow you to use those locations, you can not do anything with it really... your only option then is to include the code directly inthe JSP files, which is not a good idea...
if you are asking how to place the files in some other location... unless you hack the server source, you can't... it is coded, for security reasons to require a /WEB-INF/ location... things under this folder can not be directly accessed or referenced from outside your webapp... So I place my main pages under "webapps/myapp", for example, but then all the included stuff, is placed under "webapps/myapps/WEB-INF/"...
Peace,
![]() |
Similar Threads
Other Threads in the JSP Forum
- Previous Thread: running servlets
- Next Thread: Logging
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web





