java bean location
while using jsp:usebean where should i place my bean class?
shld i put into classes folder?or make a package first.
i have hello.jsp with following code
<jsp:useBean id="t1" class="pkg.Mybean"/>
<jsp:setProperty name="t1" property="name" value="ducat"/>
<%=t1.getName()%>
and i get error on executing:
/hello.jsp(1): class 'pkg.Mybean' could not be loaded
probably occurred due to an error in /hello.jsp line 1:
<jsp:useBean id="t1" class="pkg.Mybean"/>
Either or should work. Just remember that if you use a package name in your UseBean value, then your actual bean must also declare itself as being from that package and your jar file or classes dir must contain a directory or parent entry for each package noted. e.g: org.myco.myapp.beans.MyBean would have to either have jar entry of:
org/myco/myapp/beans/MyBean.class OR classes location of:
org/myco/myapp/beans/MyBean.class
If you use a jar, then plop the jar into your WEB-INF/lib.
If you choose not to use a package (which is discouraged), then you simply put your class in the root of your WEB-INF/classes directory e.g.: WEB-INF/classes/MyBean.class
But your bean cannot declare itself belonging to a package or else the appserver will go looking for it in the wrong spot.
> If you choose not to use a package (which is
> discouraged), then you simply put your class in the
> root of your WEB-INF/classes directory e.g.:
> WEB-INF/classes/MyBean.class
>
Not only is it discouraged, it simply wouldnt work too. All classes have to be packaged if you are using tomcat 5.0 and above.
ram.