Static imports in JSP pages

K

Kenneth P. Turvey

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.
 
M

Manish Pandit

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.

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
 
L

Lew

Manish said:
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.

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

Kenneth P. Turvey

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.
 
L

Lew

Kenneth said:
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.

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.
 
D

Daniel Pitts

Lew said:
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".
 
D

Daniel Pitts

Lew said:
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.
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.
 
L

Lew

Daniel said:
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
 
L

Lew

Daniel said:
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.
 
A

Almond

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

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?


--
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.
 
A

Almond

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.

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?

--
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.
 
D

Daniel Pitts

Andrew said:
Daniel Pitts wrote:
...

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

Nah.. doesn't quite have the same "ring" to it. ;-)
Actually, my fingers have a ring to it. Same with my wife's :)
 
A

Are Nybakk

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

Right?

Seig hail!


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.
 
L

Lew

Are said:
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/.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top