Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Static imports in JSP pages

Thread view: 
Kenneth P. Turvey - 30 Oct 2007 18:03 GMT
I've been writing a web application for a client.  It isn't a large
affair, but it is important to the client.  In so doing I've used static
imports on some of my pages.  It just makes the JSP code look a bit
cleaner.  The import I've used looks like:

<%@ page import="static com.my.domain.MyClass.*" %>

This works fine under TomCat so I assumed it was supported by the
standard.  Unfortunately when I try to run the same code under Resin, I
have no success.  

So, the question is, "Are static imports supported by the JSP standard?"
and, "If they are how does one do them in a portable manner?"  

Is Resin broken?  

Thanks.  

I've been posting a number of questions recently.  I apologize for the
extra bandwidth I've been using.  Normally I spend more time answering
questions than asking them, but lately I've run into any number of issues.

I'll try to even out the Karma balance over the next few months.  

Thanks again.

Signature

Kenneth P. Turvey <kt-usenet@squeakydolphin.com>

Manish Pandit - 30 Oct 2007 18:56 GMT
On Oct 30, 10:03 am, "Kenneth P. Turvey" <kt-
use...@squeakydolphin.com> wrote:
> I've been writing a web application for a client.  It isn't a large
> affair, but it is important to the client.  In so doing I've used static
[quoted text clipped - 24 lines]
> --
> Kenneth P. Turvey <kt-use...@squeakydolphin.com>

AFAIK, regulat imports are supported and are a part of the spec (as
the @page directive). Do you have to use static imports? I believe
they just improve the readability and have no impact on performance/
runtime.

-cheers,
Manish
Lew - 31 Oct 2007 00:40 GMT
> On Oct 30, 10:03 am, "Kenneth P. Turvey" <kt-
> use...@squeakydolphin.com> wrote:
[quoted text clipped - 31 lines]
> they just improve the readability and have no impact on performance/
> runtime.

Really he shouldn't have any imports in the JSP, because there shouldn't be
any scriptlet in the JSP.

Signature

Lew

Kenneth P. Turvey - 31 Oct 2007 01:03 GMT
> Really he shouldn't have any imports in the JSP, because there shouldn't be
> any scriptlet in the JSP.

Would you explain yourself here.  I'm not sure I understand.  

I've got very little code in the JSP at all, just a few method calls.
They are generating HTML to go in the page.

I could have used tag libraries, but they seemed like overkill at this
point.  I am unlikely to be reusing the code.  

Signature

Kenneth P. Turvey <kt-usenet@squeakydolphin.com>

Lew - 31 Oct 2007 01:15 GMT
>> Really he shouldn't have any imports in the JSP, because there shouldn't be
>> any scriptlet in the JSP.
[quoted text clipped - 6 lines]
> I could have used tag libraries, but they seemed like overkill at this
> point.  I am unlikely to be reusing the code.  

As a general rule, and of course there are exceptions, JSPs should contain
only markup and custom tags, not direct scriptlet.  Non-JSP servlets and
regular classes contain all the direct Java code.

Code in the JSP always makes trouble, to the point where I separate it out
even for small projects.

But your response shows that you know this already.  I suspect I am not
answering your question, because I can't see that I'm telling you anything
that you don't already know.

Signature

Lew

Daniel Pitts - 31 Oct 2007 02:13 GMT
>>> Really he shouldn't have any imports in the JSP, because there
>>> shouldn't be any scriptlet in the JSP.
[quoted text clipped - 15 lines]
> answering your question, because I can't see that I'm telling you
> anything that you don't already know.

If he's going to create the HTML in Java (which seems silly since JSP
was designed for that), then he is probably better off creating it in
the servlet (or in Spring MVC terms, the Controller), and then passing
that into the JSP as part of the model/request attribute.
Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Lew - 31 Oct 2007 05:30 GMT
> If he's going to create the HTML in Java (which seems silly since JSP
> was designed for that), then he is probably better off creating it in
> the servlet (or in Spring MVC terms, the Controller), and then passing
> that into the JSP as part of the model/request attribute.

Yes, you are absolutely correct.  I felt that introducing a conditional
expression within EL at this point might be overwhelming.

<input type="radio" name="logic3" id="logicYes"
       ${logic3=="yes"? "checked='checked'" : ""} /> Yes
<br />
<input type="radio" name="logic3" id="logicNo"
       ${logic3=="no"?  "checked='checked'" : ""} /> No
<br />
<input type="radio" name="logic3" id="logicWha"
       ${logic3=="wha"? "checked='checked'" : ""} /> Wha
<br />

untested

Signature

Lew

Lew - 31 Oct 2007 05:41 GMT
> If he's going to create the HTML in Java (which seems silly since JSP
> was designed for that), then he is probably better off creating it in
> the servlet (or in Spring MVC terms, the Controller), and then passing
> that into the JSP as part of the model/request attribute.

I just canceled a message that based part of its background on a whole other
thread.  I made a suggestion to someone recently where they wanted a radio
button preselected based on a previous post.  It used an attribute such as
"hasYes" which is set either to "checked=\"checked\"" or "".  The
corresponding radio button substituted an Expression Language (EL) construct
for that attribute:

 <input type="radio" name="logic3" id="logicYes"
        ${hasYes} /> Yes
 <br />
 <input type="radio" name="logic3" id="logicNo"
        ${hasNo} />  No
 <br />
 <input type="radio" name="logic3" id="logicWha"
        ${hasWha} /> Wha

If I remember EL syntax correctly, you can use a conditional expression:

 <input type="radio" name="logic3" id="logicYes"
        ${logic3=="yes"? "checked='checked'" : ""} /> Yes
 <br />
 <input type="radio" name="logic3" id="logicNo"
        ${logic3=="no"?  "checked='checked'" : ""} /> No
 <br />
 <input type="radio" name="logic3" id="logicWha"
        ${logic3=="wha"? "checked='checked'" : ""} /> Wha

Untested.  You might have to prefix the 'logic3' request variable with an
implicit scope.  I still look up the details whenever I use EL.

I deliberately left off making the radio prompts into <label>s this time.

Signature

Lew

Almond - 31 Oct 2007 06:20 GMT
>> If he's going to create the HTML in Java (which seems silly since JSP
>> was designed for that), then he is probably better off creating it in
[quoted text clipped - 32 lines]
>
>I deliberately left off making the radio prompts into <label>s this time.

Time to pay da bills, you arrogant sucker,
who has enough arrogance to pronounce the death sentences
to all those, who give a dead flying chicken wether you
are alive or dead.

Git it?

Signature

The most powerful Usenet tool you have ever heard of.
NewsMaestro v. 4.0.5 - Way Too Cool has been released.

Automatic enablement of all buttons, checkboxes and fields
depending on operation.
Templates generator improvements.

Job list improvements for new installations having no jobs
to begin with.

In some previous releases some class files were missing.
As a result, the program would not run.
Sorry for the inconvenience.

Multi-job support and other important feature additions
and various improvements and optimizations.

Web page:
http://newsmaestro.sourceforge.net/

Download page:
http://newsmaestro.sourceforge.net/Download_Information.htm

Send any feedback to newsmaestroinfo \at/ mail.ru.
Your personal info will not be released and your privacy
will be honored.

Daniel Pitts - 31 Oct 2007 07:17 GMT
*plonk*
> Git it?

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Almond - 31 Oct 2007 06:18 GMT
>>> Really he shouldn't have any imports in the JSP, because there shouldn't be
>>> any scriptlet in the JSP.
[quoted text clipped - 16 lines]
>But your response shows that you know this already.  I suspect I am not
>answering your question, because

Because you are not here to answere ANY kwestions.
Because you think you are the highest priest around,
all knowing.

Right?

Seig hail!

>I can't see that I'm telling you anything
>that you don't already know.

Then why are you saying all this crap?

Signature

The most powerful Usenet tool you have ever heard of.
NewsMaestro v. 4.0.5 - Way Too Cool has been released.

Automatic enablement of all buttons, checkboxes and fields
depending on operation.
Templates generator improvements.

Job list improvements for new installations having no jobs
to begin with.

In some previous releases some class files were missing.
As a result, the program would not run.
Sorry for the inconvenience.

Multi-job support and other important feature additions
and various improvements and optimizations.

Web page:
http://newsmaestro.sourceforge.net/

Download page:
http://newsmaestro.sourceforge.net/Download_Information.htm

Send any feedback to newsmaestroinfo \at/ mail.ru.
Your personal info will not be released and your privacy
will be honored.

Are Nybakk - 31 Oct 2007 12:33 GMT
>>>> Really he shouldn't have any imports in the JSP, because there shouldn't be
>>>> any scriptlet in the JSP.
[quoted text clipped - 27 lines]
>
> Then why are you saying all this crap?

Pardon me for butting in, but this thread has already been tainted. It
is really not professional to come with such a comment. Such behavior
ruin an otherwise fantastic forum for both newcomers and professionals.
I am a freshman to these java-groups, but already I get the impression
that Lew is a very competent java programmer that share's his view on
many subjects. If you don't like his answers you are free to look the
other way. I'd say, however, it's a good idea to listen to all opinions
no matter what you think of who's posting it. To throw nasty comments on
someone like you do is simply not acceptable behavior.

To compare Lew, or anyone else, to something that's got to do with
Nazism is just silly. That's nothing anyone here could take seriously.
On a side note, you didn't even manage to write one of two words in
proper German.
Lew - 31 Oct 2007 13:54 GMT
> Pardon me for butting in, but this thread has already been tainted. It
> is really not professional to come with such a comment.

I recommend that you killfile trolls, Are.

Thank you for the kind words.

I don't remember the reference, but in flame wars there is a natural law that
they devolve to Nazi comparisons.

I don't know what Almond said, but based on your and Daniel Pitts's responses
it must not have been nice.

As to Almond, feel free to comment all you want.  It's a public forum.  Be as
rude as you like; you're invisible anyway.

I did see one remark, thanks to Are's quote.  As a matter of fact, I am the
highest priest around, but I'm only all-knowing when I'm speaking /ex
cathedra/.  Blessings on you, Almond, and may the Goddess open your eyes and
your heart, and especially may She grant you full knowledge of your heart and
of your place in this universe.  /Benedicte/.

Signature

Lew

Daniel Pitts - 31 Oct 2007 02:10 GMT
>> On Oct 30, 10:03 am, "Kenneth P. Turvey" <kt-
>> use...@squeakydolphin.com> wrote:
[quoted text clipped - 27 lines]
> Really he shouldn't have any imports in the JSP, because there shouldn't
> be any scriptlet in the JSP.

Took the words right out of my "mouth".

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Andrew Thompson - 31 Oct 2007 05:39 GMT
...
>Took the words right out of my "mouth".

<speculative>
Snatched the letters right from beneath my fingers?
</speculative>

Nah.. doesn't quite have the same "ring" to it.  ;-)

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Daniel Pitts - 31 Oct 2007 07:15 GMT
> ...
>> Took the words right out of my "mouth".
[quoted text clipped - 4 lines]
>
> Nah.. doesn't quite have the same "ring" to it.  ;-)

Actually, my fingers have a ring to it.  Same with my wife's :-)

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.