You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by D Bamud <no...@cad.delhi.nic.in> on 2002/08/13 08:57:53 UTC

jsp in packages

Q1. Can I declare my jsp files in packages? How?

Q2. I have written a static method in one jsp page. I want to call  this
method in another jsp page. How to do it? I do not want to take this method
out from the jsp and put into a class (.java) and use it in both the jsp
files.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: jsp in packages

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 14 Aug 2002, D Bamud wrote:

> Date: Wed, 14 Aug 2002 11:20:59 +0530
> From: D Bamud <no...@cad.delhi.nic.in>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: jsp in packages
>
> > Writing functions in a JSP page (wrapped in <%! ... %> delimiters) is evil
> > ... don't even bother learning how to do it.
>
> Well not true Craig! If something is used more than ONCE one should use a
> method even inside a JSP. One could use custom tags but I believe one should
> bother to learn <%! ... %>. I recommend it :)
>

If readers of this list listen to only one piece of advice from me, PLEASE
listen to this one: Java code does not belong in well designed JSP pages
at *all*.

In JSP 1.1 and 1.2, there sometimes isn't a lot of choice about using
runtime expressions <%= ... %> in tag attributes to grab some things that
are not otherwise accessible.  In JSP 2.0, the advent of the expression
language takes away that last excuse.  And, fortunately, JSP 2.0 includes
directives that can force the page compiler to prohibit scriptlets -- you
can be sure that such directives will be used on any application I'm in
charge of, and that developers who try to undo this will be either
retrained or fired.

Besides the fact that people who start down this path succumb to spaghetti
code (I've had people proudly show off their 5000-line JSP pages --
sheesh), embedding Java code in your page seriously reduces the ability of
the JSP page compiler to generate optimized code for you.  So, besides
being less maintainable, your code will be at a competitive performance
disadvantage to that of developers who learn the correct development
habits -- not good for career advancement :-).

Craig

>
>
>
>
> > > Craig,
> > >
> > > Your response confirms what I thought. My questions was purely
> educational
> > > and not that I am having such cases in my code. Thanks for your
> response.
> > > Surely no one should put logic in the PL (jsp). But someone could define
> and
> > > use a utility method (eg putting a HTML table showing some data eg date
> etc)
> > > in jsp. I positive that this is something that could be done if not in
> > > current JSP version but in future versions. There could be a directive
> eg
> > > THIS.doit() that gets translated by the JSP engine into something like
> > > colrs$jsp.doit() (colrs.jsp is the jsp file). Though it is certainly not
> > > that important as required but could be done. Perhaps also at instance
> > > level!
> > >
> >
> > In general, that is what JSP custom tags are for.  Among other things,
> > they let you create arbitrary dynamic output, based on the parameters you
> > specify for that tag.  Good examples to look at include:
> >
> > * The JSP standard tag library (available via Apache as the 'standard"
> >   tag library at <http://jakarta.apache.org/taglibs>.
> >
> > * Tags that generate arbitrarily complex HTML output, such as the tags
> >   provided by the Struts framework <http://jakarta.apache.org.struts/>.
> >
> > However, in none of these cases do you see any processing functions being
> > stored in a JSP page and called from another - that would not conform to
> > good object oriented design principles.  Instead, you see the common
> > paradigm of using request attributes to share information within the time
> > frame of a given request, or session attributes to share information
> > across multiple requests for a given user.
> >
> > Writing functions in a JSP page (wrapped in <%! ... %> delimiters) is evil
> > ... don't even bother learning how to do it.
> >
> > > Thanks
> > >
> >
> > Craig
> >
> >
> > >
> > > ----- Original Message -----
> > > From: "Craig R. McClanahan" <cr...@apache.org>
> > > To: "Tomcat Users List" <to...@jakarta.apache.org>
> > > Sent: Tuesday, August 13, 2002 9:18 PM
> > > Subject: Re: jsp in packages
> > >
> > >
> > > >
> > > >
> > > > On Tue, 13 Aug 2002, D Bamud wrote:
> > > >
> > > > > Date: Tue, 13 Aug 2002 12:27:53 +0530
> > > > > From: D Bamud <no...@cad.delhi.nic.in>
> > > > > Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> > > > > To: Tomcat Users List <to...@jakarta.apache.org>
> > > > > Subject: jsp in packages
> > > > >
> > > > > Q1. Can I declare my jsp files in packages? How?
> > > > >
> > > >
> > > > No.  You have zero control over what package the JSP compiler
puts
> your
> > > > page in, or even what the class name of the generated servlet is.
> > > >
> > > > > Q2. I have written a static method in one jsp page. I want to call
> this
> > > > > method in another jsp page. How to do it? I do not want to take this
> > > method
> > > > > out from the jsp and put into a class (.java) and use it in both the
> jsp
> > > > > files.
> > > > >
> > > >
> > > > You need to rethink your "do not want to take this method out"
> > > > statement.  JSP pages and servlets are designed to be totally
> independent
> > > > components, and you can't get a reference to an instance of one page
> or
> > > > servlet from another.  Shared logic and shared data *must* be stored
> in
> > > > separate classes.
> > > >
> > > > And, you're going to need to understand how to organize your code
> properly
> > > > to work on larger scale projects anyway, so now is a good time to
> start.
> > > > Hint -- putting logic in your JSP pages is not a good design practice.
> > > >
> > > > Craig
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > <ma...@jakarta.apache.org>
> > > > For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> > >
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: jsp in packages

Posted by D Bamud <no...@cad.delhi.nic.in>.
> Writing functions in a JSP page (wrapped in <%! ... %> delimiters) is evil
> ... don't even bother learning how to do it.

Well not true Craig! If something is used more than ONCE one should use a
method even inside a JSP. One could use custom tags but I believe one should
bother to learn <%! ... %>. I recommend it :)





> > Craig,
> >
> > Your response confirms what I thought. My questions was purely
educational
> > and not that I am having such cases in my code. Thanks for your
response.
> > Surely no one should put logic in the PL (jsp). But someone could define
and
> > use a utility method (eg putting a HTML table showing some data eg date
etc)
> > in jsp. I positive that this is something that could be done if not in
> > current JSP version but in future versions. There could be a directive
eg
> > THIS.doit() that gets translated by the JSP engine into something like
> > colrs$jsp.doit() (colrs.jsp is the jsp file). Though it is certainly not
> > that important as required but could be done. Perhaps also at instance
> > level!
> >
>
> In general, that is what JSP custom tags are for.  Among other things,
> they let you create arbitrary dynamic output, based on the parameters you
> specify for that tag.  Good examples to look at include:
>
> * The JSP standard tag library (available via Apache as the 'standard"
>   tag library at <http://jakarta.apache.org/taglibs>.
>
> * Tags that generate arbitrarily complex HTML output, such as the tags
>   provided by the Struts framework <http://jakarta.apache.org.struts/>.
>
> However, in none of these cases do you see any processing functions being
> stored in a JSP page and called from another - that would not conform to
> good object oriented design principles.  Instead, you see the common
> paradigm of using request attributes to share information within the time
> frame of a given request, or session attributes to share information
> across multiple requests for a given user.
>
> Writing functions in a JSP page (wrapped in <%! ... %> delimiters) is evil
> ... don't even bother learning how to do it.
>
> > Thanks
> >
>
> Craig
>
>
> >
> > ----- Original Message -----
> > From: "Craig R. McClanahan" <cr...@apache.org>
> > To: "Tomcat Users List" <to...@jakarta.apache.org>
> > Sent: Tuesday, August 13, 2002 9:18 PM
> > Subject: Re: jsp in packages
> >
> >
> > >
> > >
> > > On Tue, 13 Aug 2002, D Bamud wrote:
> > >
> > > > Date: Tue, 13 Aug 2002 12:27:53 +0530
> > > > From: D Bamud <no...@cad.delhi.nic.in>
> > > > Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> > > > To: Tomcat Users List <to...@jakarta.apache.org>
> > > > Subject: jsp in packages
> > > >
> > > > Q1. Can I declare my jsp files in packages? How?
> > > >
> > >
> > > No.  You have zero control over what package the JSP compiler puts
your
> > > page in, or even what the class name of the generated servlet is.
> > >
> > > > Q2. I have written a static method in one jsp page. I want to call
this
> > > > method in another jsp page. How to do it? I do not want to take this
> > method
> > > > out from the jsp and put into a class (.java) and use it in both the
jsp
> > > > files.
> > > >
> > >
> > > You need to rethink your "do not want to take this method out"
> > > statement.  JSP pages and servlets are designed to be totally
independent
> > > components, and you can't get a reference to an instance of one page
or
> > > servlet from another.  Shared logic and shared data *must* be stored
in
> > > separate classes.
> > >
> > > And, you're going to need to understand how to organize your code
properly
> > > to work on larger scale projects anyway, so now is a good time to
start.
> > > Hint -- putting logic in your JSP pages is not a good design practice.
> > >
> > > Craig
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: jsp in packages

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 14 Aug 2002, R.C.Nougain wrote:

> Date: Wed, 14 Aug 2002 11:02:04 +0530
> From: R.C.Nougain <no...@cad.delhi.nic.in>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: jsp in packages
>
> Craig,
>
> Your response confirms what I thought. My questions was purely educational
> and not that I am having such cases in my code. Thanks for your response.
> Surely no one should put logic in the PL (jsp). But someone could define and
> use a utility method (eg putting a HTML table showing some data eg date etc)
> in jsp. I positive that this is something that could be done if not in
> current JSP version but in future versions. There could be a directive eg
> THIS.doit() that gets translated by the JSP engine into something like
> colrs$jsp.doit() (colrs.jsp is the jsp file). Though it is certainly not
> that important as required but could be done. Perhaps also at instance
> level!
>

In general, that is what JSP custom tags are for.  Among other things,
they let you create arbitrary dynamic output, based on the parameters you
specify for that tag.  Good examples to look at include:

* The JSP standard tag library (available via Apache as the 'standard"
  tag library at <http://jakarta.apache.org/taglibs>.

* Tags that generate arbitrarily complex HTML output, such as the tags
  provided by the Struts framework <http://jakarta.apache.org.struts/>.

However, in none of these cases do you see any processing functions being
stored in a JSP page and called from another - that would not conform to
good object oriented design principles.  Instead, you see the common
paradigm of using request attributes to share information within the time
frame of a given request, or session attributes to share information
across multiple requests for a given user.

Writing functions in a JSP page (wrapped in <%! ... %> delimiters) is evil
... don't even bother learning how to do it.

> Thanks
>

Craig


>
> ----- Original Message -----
> From: "Craig R. McClanahan" <cr...@apache.org>
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Sent: Tuesday, August 13, 2002 9:18 PM
> Subject: Re: jsp in packages
>
>
> >
> >
> > On Tue, 13 Aug 2002, D Bamud wrote:
> >
> > > Date: Tue, 13 Aug 2002 12:27:53 +0530
> > > From: D Bamud <no...@cad.delhi.nic.in>
> > > Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> > > To: Tomcat Users List <to...@jakarta.apache.org>
> > > Subject: jsp in packages
> > >
> > > Q1. Can I declare my jsp files in packages? How?
> > >
> >
> > No.  You have zero control over what package the JSP compiler puts your
> > page in, or even what the class name of the generated servlet is.
> >
> > > Q2. I have written a static method in one jsp page. I want to call  this
> > > method in another jsp page. How to do it? I do not want to take this
> method
> > > out from the jsp and put into a class (.java) and use it in both the jsp
> > > files.
> > >
> >
> > You need to rethink your "do not want to take this method out"
> > statement.  JSP pages and servlets are designed to be totally independent
> > components, and you can't get a reference to an instance of one page or
> > servlet from another.  Shared logic and shared data *must* be stored in
> > separate classes.
> >
> > And, you're going to need to understand how to organize your code properly
> > to work on larger scale projects anyway, so now is a good time to start.
> > Hint -- putting logic in your JSP pages is not a good design practice.
> >
> > Craig
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: jsp in packages

Posted by "R.C.Nougain" <no...@cad.delhi.nic.in>.
Craig,

Your response confirms what I thought. My questions was purely educational
and not that I am having such cases in my code. Thanks for your response.
Surely no one should put logic in the PL (jsp). But someone could define and
use a utility method (eg putting a HTML table showing some data eg date etc)
in jsp. I positive that this is something that could be done if not in
current JSP version but in future versions. There could be a directive eg
THIS.doit() that gets translated by the JSP engine into something like
colrs$jsp.doit() (colrs.jsp is the jsp file). Though it is certainly not
that important as required but could be done. Perhaps also at instance
level!

Thanks


----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Tuesday, August 13, 2002 9:18 PM
Subject: Re: jsp in packages


>
>
> On Tue, 13 Aug 2002, D Bamud wrote:
>
> > Date: Tue, 13 Aug 2002 12:27:53 +0530
> > From: D Bamud <no...@cad.delhi.nic.in>
> > Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> > To: Tomcat Users List <to...@jakarta.apache.org>
> > Subject: jsp in packages
> >
> > Q1. Can I declare my jsp files in packages? How?
> >
>
> No.  You have zero control over what package the JSP compiler puts your
> page in, or even what the class name of the generated servlet is.
>
> > Q2. I have written a static method in one jsp page. I want to call  this
> > method in another jsp page. How to do it? I do not want to take this
method
> > out from the jsp and put into a class (.java) and use it in both the jsp
> > files.
> >
>
> You need to rethink your "do not want to take this method out"
> statement.  JSP pages and servlets are designed to be totally independent
> components, and you can't get a reference to an instance of one page or
> servlet from another.  Shared logic and shared data *must* be stored in
> separate classes.
>
> And, you're going to need to understand how to organize your code properly
> to work on larger scale projects anyway, so now is a good time to start.
> Hint -- putting logic in your JSP pages is not a good design practice.
>
> Craig
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: jsp in packages

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 13 Aug 2002, D Bamud wrote:

> Date: Tue, 13 Aug 2002 12:27:53 +0530
> From: D Bamud <no...@cad.delhi.nic.in>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: jsp in packages
>
> Q1. Can I declare my jsp files in packages? How?
>

No.  You have zero control over what package the JSP compiler puts your
page in, or even what the class name of the generated servlet is.

> Q2. I have written a static method in one jsp page. I want to call  this
> method in another jsp page. How to do it? I do not want to take this method
> out from the jsp and put into a class (.java) and use it in both the jsp
> files.
>

You need to rethink your "do not want to take this method out"
statement.  JSP pages and servlets are designed to be totally independent
components, and you can't get a reference to an instance of one page or
servlet from another.  Shared logic and shared data *must* be stored in
separate classes.

And, you're going to need to understand how to organize your code properly
to work on larger scale projects anyway, so now is a good time to start.
Hint -- putting logic in your JSP pages is not a good design practice.

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>