• Post Reply Bookmark Topic Watch Topic
  • New Topic

Usebean: Fully qualified class name only?  RSS feed

 
manoj rajkumar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1>Is it necessary that we always pass the fully qualified classname to the class attribute in useBean?

i.e. Why can't we replace:
<jsp:useBean id="bean1" class="bean.SimpleBean" />
with
<%@ page import="bean.*" %>
<jsp:useBean id="bean1" class="SimpleBean" />
(assuming SimpleBean class is in the bean package.)

2> A jsp spec says that it should be fully qualified name only?
3> If yes, is it not a design flaw so to say?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1> Yes it is necessary
2> The JSP specification is clear about this : refer to JSP.5.1 <jsp:useBean>
3> A flaw ? Why do you think this would be ?
 
manoj rajkumar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, we could have specified the directories to look for in
<@page import="dName">
and then used only the class name in the useBean directive.

When I said flaw, I meant lacking flexibility.

Is there any reason why we should specify the fully qualified class only?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would using an unqualified name make it more flexible?
 
manoj rajkumar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben, In the java classes , we generally have import java.io.* and then use PrintWriter,OutputStream etc. instead of fully qualified class name everywhere else.

Java class:

import java.io.*;
.
.
.
PrintWriter out= ... // Note Fully qual. name not required here.
FileInputStream fin=...

so we could have done something similar to that:
Jsp:

<@page import="com.manoj.myPackage.*">
<jsp:useBean id="bean1" class="ManojBean" />
|
|
Fully Qualified name not required since we are importing


I was thinking in that perspective. But I guess it is just a decision that the designers of the jsp have made and we can follow up with the fully qualified class name.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!