Bug 15688

Summary: full-qualified names instead of imports
Product: Tomcat 4 Reporter: Sven <sven.koehler>
Component: Jasper 2Assignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P3    
Version: 4.1.17   
Target Milestone: ---   
Hardware: Other   
OS: other   

Description Sven 2002-12-27 22:30:47 UTC
Hi,

Jasper generated *.java-files that are compiled.
The template for those files is very "unaesthetic".

I could demonstrate nice side-effects using a simple
  <%@ page import="mypackage.Jspfactory" %>

You should use full qualified names instead of a bunch of import-staments.
For example
  _jspxFactory = JspFactory.getDefaultFactory();
would become
  _jspxFactory = javax.servlet.jsp.JspFactory.getDefaultFactory();
and if you don't already do,
you should use the this-reference where possible.

I don't know what the spec says about that conflict, but it shouldn't be a bad
idea to use full-qualified names instead of imports.
Comment 1 Mark Thomas 2004-02-28 13:38:11 UTC
There are several obvious workarounds if you experience problems of this type:
- use fully-qualified domain names rather than imports yourself;
- write the servlet directly.

I am changing this to an enhancement request although I doubt that there will 
be much enthusiasm to make the proposed changes.
Comment 2 Sven 2004-02-28 14:01:52 UTC
It would be cleverer to avoid problems, so think about it.
Comment 3 Mark Thomas 2011-01-11 17:51:38 UTC
The spec requires certain packages to be imported. It also reserves the name space used by the local variables.
Comment 4 Sven 2011-01-11 18:10:11 UTC
(In reply to comment #3)
> The spec requires certain packages to be imported. It also reserves the name
> space used by the local variables.

I'm reopening, because your response fails to answer the questions that have been raised: It's obvious, that the spec says that certain packages are to be imported. However, does the spec say, what happens if another import "shadows" the import of those packages?

I guess, nothing in the spec prevents you from using the fully qualified classnames. (I'm not asking your to remove the imports - that would clearly violate the spec.)
Comment 5 Mark Thomas 2011-01-12 04:16:49 UTC
The original issue description requested that Jasper "use full-qualified names instead of imports". The key phrase being "instead of" which is what prompted me to close this as invalid.

The spec isn't as explicit as I would like but there are hints (e.g. the method signature in table JSP.9-1) that Tomcat's current implementation is what spec authors were intending.

That said, and as you point out, there is no harm in using fully qualified class names. My biggest concern (before I read the spec in more detail) was if the imports were removed and a class name was over-looked that a bug would be introduced. With the imports still in place, that won't be an issue.

I'll look at adding the explicit class names to Tomcat 7 later today. I don't intend proposing this for back-port.
Comment 6 Mark Thomas 2011-01-12 07:08:37 UTC
Fixed in 7.0.x and will be in 7.0.7 onwards.
Comment 7 Sven 2011-01-12 08:05:20 UTC
(In reply to comment #5)
> The original issue description requested that Jasper "use full-qualified names
> instead of imports". The key phrase being "instead of" which is what prompted
> me to close this as invalid.

Oh I see what you mean. I'm sorry. This was misleading.

> I'll look at adding the explicit class names to Tomcat 7 later today. I don't
> intend proposing this for back-port.

(In reply to comment #6)
> Fixed in 7.0.x and will be in 7.0.7 onwards.

Thank you for reconsidering and fixing this.