File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Problem with using  jsp:useBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with using  jsp:useBean" Watch "Problem with using  jsp:useBean" New topic
Author

Problem with using jsp:useBean

Rahesh Kumar
Ranch Hand

Joined: Sep 10, 2004
Posts: 53
Hi,

I have a JSP file in which I declared a bean using <jsp:useBean> like the one below

<jsp:useBean id="currentArea"
type = "com.sapmarkets.isa.catalog.webcatalog.WebCatArea"
scope="request" >

and in the same jsp,I have one include <%@ include file="/catalog/B2CPath.jsp"%>

and in the B2CPath.jsp , i try to use the currentArea

String searchQuery = null;
searchQuery = ((com.sapmarkets.isa.catalog.webcatalog.WebCatArea)request.getAttribute("currentArea")).getAreaName();

When I try this, I get 'bean currentArea not within the scope' exception .Please let me know what could be the cause of the problem. How it can be resolved?.Thanks in advance

Rahesh
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you are expecting your <jsp:usebean> tag to instantiate the bean, you must provide a class attribute for the tag. Example:


Merrill
Consultant, Sima Solutions
Rahesh Kumar
Ranch Hand

Joined: Sep 10, 2004
Posts: 53
Hey Merrill,

I tried that too, I am getting an InstatntiationException, the stack trace is as below

javax.servlet.ServletException: class com.sapmarkets.isa.catalog.webcatalog.WebCatArea : java.lang.InstantiationException: com.sapmarkets.isa.catalog.webcatalog.WebCatArea
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:498)
at org.apache.jsp.catalog.ProductDetailB2C_jsp._jspService(ProductDetailB2C_jsp.java:1209)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:627)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:306)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at com.sapmarkets.isa.core.ActionServlet.processActionForward(ActionServlet.java:267)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at com.sapmarkets.isa.core.ActionServlet.process(ActionServlet.java:430)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:627)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:306)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at com.sapmarkets.isa.core.ActionServlet.processActionForward(ActionServlet.java:267)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at com.sapmarkets.isa.core.ActionServlet.process(ActionServlet.java:430)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:627)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:306)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at com.sapmarkets.isa.core.ActionServlet.processActionForward(ActionServlet.java:267)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at com.sapmarkets.isa.core.ActionServlet.process(ActionServlet.java:430)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:627)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:306)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at com.sapmarkets.isa.core.ActionServlet.processActionForward(ActionServlet.java:267)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at com.sapmarkets.isa.core.ActionServlet.process(ActionServlet.java:430)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:627)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:306)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at com.sapmarkets.isa.core.ActionServlet.processActionForward(ActionServlet.java:267)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at com.sapmarkets.isa.core.ActionServlet.process(ActionServlet.java:430)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:627)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:306)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at com.sapmarkets.isa.core.ActionServlet.processActionForward(ActionServlet.java:267)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at com.sapmarkets.isa.core.ActionServlet.process(ActionServlet.java:430)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:627)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:306)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at com.sapmarkets.isa.core.ActionServlet.processActionForward(ActionServlet.java:267)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at com.sapmarkets.isa.core.ActionServlet.process(ActionServlet.java:430)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at com.worldbank.eservices.security.SessionInitFilter.filterChain(SessionInitFilter.java:148)
at com.worldbank.eservices.security.SessionInitFilter.filterHttp(SessionInitFilter.java:94)
at com.worldbank.eservices.security.SessionInitFilter.doFilter(SessionInitFilter.java:63)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at com.worldbank.eservices.security.AuthTokenExistsFilter.doFilterInternal(AuthTokenExistsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534

Thanks
Rahesh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61596
    
  67

Does the WebCatArea class follow all the rules of a JavaBean? Has a no-args constructor, for example?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rahesh Kumar
Ranch Hand

Joined: Sep 10, 2004
Posts: 53
No it does not have a no-arg constructor
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
It should have a no-arg constructor otherwise it couldn't start from the JSP.
You found your problem.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61596
    
  67

Originally posted by Rahesh Kumar:
No it does not have a no-arg constructor


Yup, as Remko said, that's the problem. Without a no-args constructor, how is the container to know how to create an instance of your class?
Rahesh Kumar
Ranch Hand

Joined: Sep 10, 2004
Posts: 53
Ye, Thanks. actually this code is being customised , so I did not have the actual source with me. Once I found the source code, I found the problem. Thanks for your help guys...

Thanks
Rahesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with using jsp:useBean