In HFSJ, the statement is made that in the jsp:useBean tag, if you only specify the type and not the class, the bean must exist as an attribute and already be in the defined scope. e.g., page scope. I have a question about this. If the bean object is set as an attribute in the request, that's fine, but if I specify a scope of page or specify no scope at all, which equals page, since the jsp:useBean tag typically comes at the beginning of the JSP, the bean is not, I would think, in page scope yet because the request object has not been processed by the JSP (except perhaps under the covers). So will it ever work to specify type and not class for a bean that exists as a request attribute if not scope is specified? Thanks.
I don't think it's common in the real world to use type without class. In fact, I'm straining my brain to think if I've ever used jsp:useBean.
There might be some scenarios where the file containing jsp:useBean might make sense to expect a page scoped bean if you knew the JSP was never used independently, meaning you know it is always used via include. I seriously doubt if I'd write something like that, but still.
Do you mean : if you use jsp:useBean without to specify a scope - then the bean in in the page scope, that means before the jsp:useBean you must add the bean in to the scope. If this is what you mean you are right you must register the bean before usage. There is one scenario when you don't need to do this - on static include (@include file =".."), in this case the included file is just copied (inserted) on a certain position in your jsp, and this position can be after the point where you register the bean (in the page scope).
I don't think there's any problem here, and I think you're saying two different things, but I may be missing something. If the bean is not in the session, you should not use useBean with a session scope and only a type. Same for the page scope. If the bean is not in the page, you should not use useBean with a page scope and only a type. Same problem, with a different scope.
You have some chances to put the bean in the session before forwarding to the page. Same for the page scope. You're still allowed to make the bean before the useBean tag. But using what ? A scriplet ? That would be meaningless.
So will it ever work to specify type and not class for a bean that exists as a request attribute if not scope is specified?
As a request attribute ? That's a different question, isn't it ? If you don't set the scope, useBean will look into the page scope. If the bean is in the request, it will fail. (same comment as Rakesh)