You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jeff Ousley <je...@yahoo.com> on 2003/01/13 19:49:51 UTC

jsp versus xml syntax

Hello!

I'm using (learning) tomcat-4.1.18 and I'm trying to
get the following example page to work:



<HTML>
<jsp:declaration>
// this is a local "helper" bean for processing the
HTML form
static public class localBean
{
   private String value;
   public String getValue()         { return value;}
   public void setValue(String s)   { value = s; }
}
</jsp:declaration>

<jsp:useBean id="localBean" scope="page"
class="localBean" >
<%-- Every time we create the bean, initialize the
string  --%>
<jsp:setProperty name="localBean" property="value"
value="World" />
</jsp:useBean>

<%-- Whatever HTTP parameters we have,
     try to set an analogous bean property  --%>
<jsp:setProperty name="localBean" property="*" />

<HEAD><TITLE>HelloWorld w/ JavaBean</TITLE></HEAD>
<BODY>
<CENTER>
<P><H1>Hello
<jsp:getProperty name='localBean'
property='value'/></H1></P>
<FORM method=post>
Enter a name to be greeted: 
<INPUT TYPE="text" SIZE="32" NAME="value"
VALUE="<jsp:getProperty name='localBean'
property='value'/>">
<BR>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</CENTER>
</BODY>
</HTML>



I think I'm having trouble first of all because much
of the syntax is in xml form not jsp form. Is this
correct? How do I use the xml syntax under tomcat 4?
I'm very new and still learning.

thanks!
-jeff

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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


RE: jsp versus xml syntax

Posted by "Noel J. Bergman" <no...@devtech.com>.
> The first snippet works if and only if your jsp file is entirely
> XML-formatted.

That was not true in earlier versions of the JSP specification, and is
explicitly changed in JSP v2.0.  XML syntax in user author pages is only
broken in the current JSP specification.

	--- Noel


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


RE: jsp versus xml syntax

Posted by Jeff Ousley <je...@yahoo.com>.
Greg,

Thanks. Finally a thorough answer that makes sense. I
really appreciate it.

-jeff

--- Greg Trasuk <st...@on.aibn.com> wrote:
> 	The first snippet works if and only if your jsp
> file is entirely
> XML-formatted.  Specifically, you need to:
> 
> (1) have an xml declaration at the beginning of the
> file (i.e <?xml
> version='1.0'?>).
> (2) Enclose the whole thing in a <jsp:root> element
> with the correct
> namespace (see the spec for details)
> (3) Ensure that the whole document is well-formed
> XML (i.e. start tags have
> end tags, tags nest properly, attributes are quoted,
> etc).
> 
> 	In (3) lies the rub, especially if you're
> generating HTML.  HTML is not,
> and cannot be well-formed, so you have to enclose
> your HTML portions in a
> CDATA section.  It's a lot of extra work if you're
> editing jsp files by
> hand.  Hence Craig's comment that the XML syntax is
> for tools, not people.
> It's intended for auto-generation, IDE-type editors,
> etc, not for generating
> jsp files manually.
> 
> 	To make things a little more confusing, at least
> one container (IBM
> Websphere) seems to accept XML syntax as direct
> subsitution for the JSP
> syntax, but it's in violation of the JSP specs and
> you should stick to the
> spec to ensure portability.  You can get the spec
> at:
>
http://jcp.org/aboutJava/communityprocess/first/jsr053/index.htmlhttp://jcp.
>
org/aboutJava/communityprocess/first/jsr053/index.html
> 
> 	Short answer- you can and probably should forget
> about the XML syntax for
> JSP pages.
> 
> Cheers,
> 
> Greg Trasuk, President
> StratusCom Manufacturing Systems Inc. - We use
> information technology to
> solve business problems on your plant floor.
> http://stratuscom.ca
> 
> >-----Original Message-----
> >From: Jeff Ousley [mailto:jeofatima@yahoo.com]
> >Sent: January 13, 2003 16:16
> >To: Tomcat Users List
> >Subject: Re: jsp versus xml syntax
> >
> >
> >So, under tomcat 4.1 am I not able to do this:
> >
> ><jsp:declaration>
> >// this is a local "helper" bean for processing the
> >HTML form
> >static public class localBean
> >{
> >   private String value;
> >   public String getValue()         { return
> value;}
> >   public void setValue(String s)   { value = s; }
> >}
> ></jsp:declaration>
> >
> >
> >but instead have to do this:
> >
> ><%!
> >// this is a local "helper" bean for processing the
> >HTML form
> >static public class localBean
> >{
> >   private String value;
> >   public String getValue()         { return
> value;}
> >   public void setValue(String s)   { value = s; }
> >}
> >%>
> >
> >
> >>From everything I can tell/read, the first snippet
> >(using the xml syntax) should work, but I can't
> seem
> >to get it to.
> >
> >thanks!
> >-jeff
> >--- Robert Horton <ro...@rthorton.freeserve.co.uk>
> >wrote:
> >> Hi,
> >> >
> >> > I think I'm having trouble first of all because
> >> much
> >> > of the syntax is in xml form not jsp form. Is
> this
> >> > correct? How do I use the xml syntax under
> tomcat
> >> 4?
> >> > I'm very new and still learning.
> >>
> >> It goes:
> >>
> >> jsp -> xml (or html) -> rendered by browser
> >>
> >> i.e. the jsp is executed by the server to produce
> >> the xml (being a
> >> superset of html) which is then passed to the
> >> browser.
> >>
> >> Hope that helps,
> >> R
> >>
> >> --
> >> To unsubscribe, e-mail:
> >>
> <ma...@jakarta.apache.org>
> >> For additional commands, e-mail:
> >> <ma...@jakarta.apache.org>
> >>
> >
> >
> >__________________________________________________
> >Do you Yahoo!?
> >Yahoo! Mail Plus - Powerful. Affordable. Sign up
> now.
> >http://mailplus.yahoo.com
> >
> >--
> >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>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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


RE: jsp versus xml syntax

Posted by Greg Trasuk <st...@on.aibn.com>.
	The first snippet works if and only if your jsp file is entirely
XML-formatted.  Specifically, you need to:

(1) have an xml declaration at the beginning of the file (i.e <?xml
version='1.0'?>).
(2) Enclose the whole thing in a <jsp:root> element with the correct
namespace (see the spec for details)
(3) Ensure that the whole document is well-formed XML (i.e. start tags have
end tags, tags nest properly, attributes are quoted, etc).

	In (3) lies the rub, especially if you're generating HTML.  HTML is not,
and cannot be well-formed, so you have to enclose your HTML portions in a
CDATA section.  It's a lot of extra work if you're editing jsp files by
hand.  Hence Craig's comment that the XML syntax is for tools, not people.
It's intended for auto-generation, IDE-type editors, etc, not for generating
jsp files manually.

	To make things a little more confusing, at least one container (IBM
Websphere) seems to accept XML syntax as direct subsitution for the JSP
syntax, but it's in violation of the JSP specs and you should stick to the
spec to ensure portability.  You can get the spec at:
http://jcp.org/aboutJava/communityprocess/first/jsr053/index.htmlhttp://jcp.
org/aboutJava/communityprocess/first/jsr053/index.html

	Short answer- you can and probably should forget about the XML syntax for
JSP pages.

Cheers,

Greg Trasuk, President
StratusCom Manufacturing Systems Inc. - We use information technology to
solve business problems on your plant floor.
http://stratuscom.ca

>-----Original Message-----
>From: Jeff Ousley [mailto:jeofatima@yahoo.com]
>Sent: January 13, 2003 16:16
>To: Tomcat Users List
>Subject: Re: jsp versus xml syntax
>
>
>So, under tomcat 4.1 am I not able to do this:
>
><jsp:declaration>
>// this is a local "helper" bean for processing the
>HTML form
>static public class localBean
>{
>   private String value;
>   public String getValue()         { return value;}
>   public void setValue(String s)   { value = s; }
>}
></jsp:declaration>
>
>
>but instead have to do this:
>
><%!
>// this is a local "helper" bean for processing the
>HTML form
>static public class localBean
>{
>   private String value;
>   public String getValue()         { return value;}
>   public void setValue(String s)   { value = s; }
>}
>%>
>
>
>>>From everything I can tell/read, the first snippet
>(using the xml syntax) should work, but I can't seem
>to get it to.
>
>thanks!
>-jeff
>--- Robert Horton <ro...@rthorton.freeserve.co.uk>
>wrote:
>> Hi,
>> >
>> > I think I'm having trouble first of all because
>> much
>> > of the syntax is in xml form not jsp form. Is this
>> > correct? How do I use the xml syntax under tomcat
>> 4?
>> > I'm very new and still learning.
>>
>> It goes:
>>
>> jsp -> xml (or html) -> rendered by browser
>>
>> i.e. the jsp is executed by the server to produce
>> the xml (being a
>> superset of html) which is then passed to the
>> browser.
>>
>> Hope that helps,
>> R
>>
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>
>
>
>__________________________________________________
>Do you Yahoo!?
>Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
>http://mailplus.yahoo.com
>
>--
>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 versus xml syntax

Posted by Jeff Ousley <je...@yahoo.com>.
So, under tomcat 4.1 am I not able to do this:

<jsp:declaration>
// this is a local "helper" bean for processing the
HTML form
static public class localBean
{
   private String value;
   public String getValue()         { return value;}
   public void setValue(String s)   { value = s; }
}
</jsp:declaration>


but instead have to do this:

<%!
// this is a local "helper" bean for processing the
HTML form
static public class localBean
{
   private String value;
   public String getValue()         { return value;}
   public void setValue(String s)   { value = s; }
}
%>


>From everything I can tell/read, the first snippet
(using the xml syntax) should work, but I can't seem
to get it to.

thanks!
-jeff
--- Robert Horton <ro...@rthorton.freeserve.co.uk>
wrote:
> Hi,
> > 
> > I think I'm having trouble first of all because
> much
> > of the syntax is in xml form not jsp form. Is this
> > correct? How do I use the xml syntax under tomcat
> 4?
> > I'm very new and still learning.
> 
> It goes:
> 
> jsp -> xml (or html) -> rendered by browser
> 
> i.e. the jsp is executed by the server to produce
> the xml (being a
> superset of html) which is then passed to the
> browser.
> 
> Hope that helps,
> R
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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


Re: jsp versus xml syntax

Posted by Robert Horton <ro...@rthorton.freeserve.co.uk>.
Hi,
> 
> I think I'm having trouble first of all because much
> of the syntax is in xml form not jsp form. Is this
> correct? How do I use the xml syntax under tomcat 4?
> I'm very new and still learning.

It goes:

jsp -> xml (or html) -> rendered by browser

i.e. the jsp is executed by the server to produce the xml (being a
superset of html) which is then passed to the browser.

Hope that helps,
R

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


Re: jsp versus xml syntax

Posted by Peter Harrison <pe...@asterisk.co.nz>.
On Wed, 15 Jan 2003 10:45, Erik Price wrote:

> But in that JSP, there is a conditional test to determine whether or not
> certain links should be displayed.  Namely, administrative functions
> should not be displayed to users who don't have administrative access.
> The way I have it right now is an "if" statement in a scriptlet, which
> displays the appropriate HTML depending on the user's session
> information (the user is represented with a bean, and it checks one of
> the properties of the bean to make this decision).
>
> I know that this is how a lot of JSPs are written, so it's not
> necessarily *bad*.  But you seem to be hinting at a better way of doing
> it.  My best guess is that you're referring to creating a custom tag of
> some sort that displays the navigation, and the logic for what to
> display should be tucked away into the tag definition?  I'm only
> guessing here.  If you could expound a bit that would be helpful for a
> lot of us, I'm sure.

The problem is essentially one of demarkation. If you say its okay for a 
developer to add a little bit of code they might get the idea its okay to add 
a little more. When its easier to add a little bit of code to a JSP to fix a 
problem you will do it - because the negitive design consequences are down 
the track. Its easier to have a hard and fast rule than to have a fuzzy rule 
that leads to misunderstandings.

Some problems you run into when putting code into a JSP :

- It makes it dificult to write unit tests for the included code.
- reduces and discourages the reuse of code.
- encourages 'cut and paste' - which reduces maintainability.
- means that page designers and coders work on the same file.

I personally like to use velocity with struts, as velocity doesn't allow 
business logic in HTML, is less verbose, and doesn't have the same debugging 
issues I found with JSP. Struts allows a rather elegant solution to the 
problem mentioned above about having multiple response pages to a single 
request.

<shameless plug>
For those interested about my thinking and approach with Velocity you might 
like to read the book I co-authored called 'Mastering Tomcat Development'.
</shameless plug>

Regards,

Peter Harrison

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


RE: jsp versus xml syntax

Posted by "Noel J. Bergman" <no...@devtech.com>.
> Since all of my JSPs in my site will need a navigation bar, I have
> sectioned the navigation bar off into its own JSP file ...

Basically, you are creating an "HTML widget", a hopefully common practice.

> But in that JSP, there is a conditional test to determine whether or not
> certain links should be displayed.

There are conditional JSTL tags that you could use based upon the value of
some bean property.  They aren't any less "programming" than a simple
if-statement, but they allow the page to not have any Java code.

	--- Noel


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


Re: jsp versus xml syntax

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

On Tue, 14 Jan 2003, Erik Price wrote:

> Date: Tue, 14 Jan 2003 16:45:43 -0500
> From: Erik Price <ep...@ptc.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: jsp versus xml syntax
>
>
>
> Craig R. McClanahan wrote:
>
> > I feel that users who use variable declarations, function declarations,
> > and scriptlets in JSP pages *at all* (no matter what syntax) are probably
> > making a mistake.  Mixing Java code with JSP code is likely to lead to a
> > morass of spaghetti that mixes business logic and presentation logic
> > together, and will ultimately make maintenance much harder.
>
> I'm going to question this but not because I disagree but rather b/c I'm
> new and am always willing to listen to advice.
>
> Since all of my JSPs in my site will need a navigation bar, I have
> sectioned the navigation bar off into its own JSP file, which is then
> included into the main JSP files (at compile time).  This is nice
> because if I change the navigation system in one place, it is changed
> across the site and I don't have to repair every single JSP.
>
> But in that JSP, there is a conditional test to determine whether or not
> certain links should be displayed.  Namely, administrative functions
> should not be displayed to users who don't have administrative access.
> The way I have it right now is an "if" statement in a scriptlet, which
> displays the appropriate HTML depending on the user's session
> information (the user is represented with a bean, and it checks one of
> the properties of the bean to make this decision).
>
> I know that this is how a lot of JSPs are written, so it's not
> necessarily *bad*.  But you seem to be hinting at a better way of doing
> it.  My best guess is that you're referring to creating a custom tag of
> some sort that displays the navigation, and the logic for what to
> display should be tucked away into the tag definition?  I'm only
> guessing here.  If you could expound a bit that would be helpful for a
> lot of us, I'm sure.
>

This is a pretty good example use case, that we can use to illustrate how
JSP has matured over the years, and also explain *why* you see so many
pages with this sort of thing (and yes, I do consider it to be a poor
practice to use a scriptlet for this).

Let's take a concrete case where you're simply checking for the existence
of a particular request attribute as your decision rule.

In the early days (1.0) of JSP, there wasn't really much choice -- you had
to write a scriptlet to get conditional behavior:

    <% if (request.getAttribute("foo")) { %>
      ... foo is present ...
    <% } else { %>
      ... foo is absent ...
    <% } %>

which, of course, gets confusing because there are so many punctuation
symbols, and you have to remember to use braces around all the conditional
blocks.  You'd be amazed at how frustrated an HTML page author can get
trying to get this right.

In JSP 1.1, we gained the ability to write custom tags, which lets you
encapsulate Java code inside what looks (to the page developer) like a
tag.  Several tag libraries became available to do lots of simple things,
including the Jakarta Taglibs project (http://jakarta.apache.org/taglibs).
Further, MVC frameworks like Struts (http://jakarta.apache.org/struts)
started to become available, and offered a way to architect your entire
application in a way that maximizes the separation between the business
layer and the presentation layer.  Among other things, Struts also
includes tags in its tag library that work for this use case:

    <logic:present name="foo" scope="request">
      ... foo is present ...
    </logic:present>
    <logic:notPresent name="foo" scope="request">
      ... foo is not present ...
    </logic:notPresent>

Page authors are more used to tag syntax than they are to programming
syntax, so this makes more sense, but it is somewhat wordy.  (Part of that
is because Struts does not have an "else" concept in its tags -- long
story, but it's not easy to do an elegant if-then-else with tags).

Custom tags are not that hard to write -- IF you are a Java programmer,
and if you can get your head around the complexities of the invocation
protocol (you have to implement several methods, and deal with the fact
that your tag instance might get pooled, ...).

JSP 1.2 improved many things about JSP, but didn't change the basic model
for tags much.  However, a parallel effort called the JSP Standard Tag
Library (JSTL) was started to standardize the most common sorts of tags
that everybody needs.  In addition, it became clear that page authors *do*
tend to understand at least a little programming syntax, depending on
their exposure to JavaScript.  In particular, JavaScript variable
references (with the "." operator) were fairly easy to grasp.

JSTL 1.0 was released last June, (the reference implementation is based on
the "standard" tag library at Jakarta Taglibs, so it's freely available),
and formalized standard versions of tags for conditionals, iteration,
formatting, XML processing, and such.  In addition, it defined an
"expression language" (EL) that can be used a syntax as close as we could
get to JavaScript/ECMAScript.  For example (not the same use case as
above), you can say things like:

  <c:if test="${customer.type = 'Special'}">
    ... display options for special customer ...
  </c:if>

where "customer.type" essentially says "go find the 'customer' bean in
whatever scope it lives in, and call getType() method on it."

JSTL can be used on any JSP 1.2 platform (such as Tomcat 4.x), just like
any other tag library.  However, EL expressions only work in the
attributes of JSTL tags (although some other tag libraries are adopting
this syntax as well -- Struts 1.1 now includes a version of the Struts
tags that have been EL-enabled, for example).

JSP 2.0, among other things, incorporates the new EL syntax.  And not just
in tag attributes, but *anywhere* in the page.  So, if you need to write
out a customer name to the output page,instead of saying something like:

  <% out.println(customer.getName()) %>

or (slightly shorter for this particular scenario):

  <%= customer.getName() %>

or the "official" JSP 1.x way to do it:

  <jsp:getProperty name="customer" property="name"/>

you can now say:

  ${customer.name}

in your page.  Of course, we're barely touching the surface of what you
can do with expressions, but basically there's almost no scenario where
the only way to solve a problem is to use a scriptlet when you've got this
kind of power available, and presented in a way that is much more
understandable to page authors.

There's *lots* of other cool things coming in JSP 2.0 (including the
ability to essentially create a custom tag out of a chunk of JSP code,
without writing any Java, and reuse it).  JSP 2.0 is part of J2EE 1.4,
which will go final this year.  Tomcat 5 will support it, as will all
other J2EE vendors when they get their 1.4 based products out.

The bottom line, though, is that much (probably more than half) of the
books and articles about JSP that you can find focus on the 1.0 and 1.1
syntax, and they don't show you how to do things differently.

I try to encourage newcomers to adopt good habits in the first place --
that's one of the reasons I created Struts, because way too many people
were trying to mix the Java code to process forms into the same JSP pages
that contain the forms themselves -- this works for "guest book" sized
apps, but quickly becomes a maintenance nightmare on large projects.

The more recent books about JSP, JSTL, and web app frameworks are starting
to get this right.  If you are into book learning, I'd strongly encourage
you to get one of the recent texts (look for JSP 1.2 coverage) that
encourages practices that will help keep your pages understandable and
maintainable.

And if you've got a 5000-line JSP page that has "all in one" support for
three input forms and four follow-up screens, all controlled by "if"
statements in scriptlets, well ... please don't show it to me :-).  Its
almost dinner time, and I don't want to lose my appetite :-).

>
> Thanks,
>
> Erik
>

Craig


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


Re: jsp versus xml syntax

Posted by Erik Price <ep...@ptc.com>.

Craig R. McClanahan wrote:

> I feel that users who use variable declarations, function declarations,
> and scriptlets in JSP pages *at all* (no matter what syntax) are probably
> making a mistake.  Mixing Java code with JSP code is likely to lead to a
> morass of spaghetti that mixes business logic and presentation logic
> together, and will ultimately make maintenance much harder.

I'm going to question this but not because I disagree but rather b/c I'm 
new and am always willing to listen to advice.

Since all of my JSPs in my site will need a navigation bar, I have 
sectioned the navigation bar off into its own JSP file, which is then 
included into the main JSP files (at compile time).  This is nice 
because if I change the navigation system in one place, it is changed 
across the site and I don't have to repair every single JSP.

But in that JSP, there is a conditional test to determine whether or not 
certain links should be displayed.  Namely, administrative functions 
should not be displayed to users who don't have administrative access. 
The way I have it right now is an "if" statement in a scriptlet, which 
displays the appropriate HTML depending on the user's session 
information (the user is represented with a bean, and it checks one of 
the properties of the bean to make this decision).

I know that this is how a lot of JSPs are written, so it's not 
necessarily *bad*.  But you seem to be hinting at a better way of doing 
it.  My best guess is that you're referring to creating a custom tag of 
some sort that displays the navigation, and the logic for what to 
display should be tucked away into the tag definition?  I'm only 
guessing here.  If you could expound a bit that would be helpful for a 
lot of us, I'm sure.


Thanks,

Erik


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


RE: Servlet Mapping Bug?

Posted by Jacob Kjome <ho...@visi.com>.
Are you sure this is happening when you go directly to Tomcat rather than 
through Apache?  All my mappings in web.xml make no mention of the context 
name and work just fine.

Try you app at:

http://localhost:8080/control/

Then try it at:

http://localhost/control/

If it works in the former case but not in the latter, then the bug is with 
your mod_jk config or the Coyote JK/JK2 connector, not with Tomcat in general.

Jake

At 03:16 PM 1/15/2003 +0000, you wrote:
>This is a bug, as I've now checked the Servlet Specification v2.3:
>
>The key phrase is:
>The path used for mapping to a servlet is the request URL from the request
>object minus the context path.
>ie for my /control/plots/x.jpg request, the context path is /control, so
>only /plots/x.jpg should be used to map the servlet.
>
>I guess this bug is probably in the Coyote Connector?
>
>Andy
>
>PS
>Here's the full text of the relevant bit from the servlet spec:
>
>SRV.11.1 Use of URL Paths
>Upon receipt of a client request, the web container determines the web
>application to which to forward it. The web application selected must have
>the longest context path that matches the start of the request URL.
>
>The matched part of the URL is the context path when mapping to servlets.
>The web container next must locate the servlet to process the request using
>the path mapping procedure described below:
>The path used for mapping to a servlet is the request URL from the request
>object minus the context path. The URL path mapping rules below are used in
>order. The first successful match is used with no further matches attempted:
>
>1. The container will try to find an exact match of the path of the request
>to the path of the servlet. A successful match selects the servlet.
>
>2. The container will recursively try to match the longest path-prefix: This
>is done by stepping down the path tree a directory at a time, using the '/'
>character as a path separator. The longest match determines the servlet
>selected.
>
>3. If the last segment in the URL path contains an extension (e.g. .jsp),
>the servlet
>container will try to match a servlet that handles requests for the
>extension.
>An extension is defined as the part of the last segment after the last '.'
>character.
>
>4. If neither of the previous three rules result in a servlet match, the
>container will
>attempt to serve content appropriate for the resource requested. If a
>"default"
>servlet is defined for the application, it will be used.
>The container must use case-sensitive string comparisons for matching.
>
>Note 1. Previous versions of this specification made use of these mapping
>techniques a suggestion rather than a requirement, allowing servlet
>containers to each have their different schemes for mapping client requests
>to servlets.
>
> > -----Original Message-----
> > From: Andy Eastham [mailto:andy.eastham@gliant.com]
> > Sent: 14 January 2003 22:46
> > To: Tomcat Users List
> > Subject: Servlet Mapping Bug?
> >
> >
> > Hi,
> >
> > I've just upgraded from Tomcat 4.0.4b1 and apache 1.3 using warp to Tomcat
> > 4.1.18 and Apache 2.0.43 using mod_jk2.
> >
> > I use a feature of servlet mapping in web.xml, where I map any
> > request under
> > a particular directory to a single servlet.  My application is mapped from
> > Apache under the url "/control/" and I invoke myServlet with any
> > request to
> > the "plots" subdirectory.  In the old configuration, the relevant
> > part of my
> > web.xml looked like:
> >
> >     <servlet-mapping>
> >         <servlet-name>
> >             myServlet
> >         </servlet-name>
> >         <url-pattern>
> >             /plots/*
> >         </url-pattern>
> >     </servlet-mapping>
> >
> > However, in my new setup, I have had to change this to make it work:
> >
> >     <servlet-mapping>
> >         <servlet-name>
> >             myServlet
> >         </servlet-name>
> >         <url-pattern>
> >             /control/plots/*
> >         </url-pattern>
> >     </servlet-mapping>
> >
> > ie put the full URI in the url-pattern, not just the path relative to the
> > Tomcat application root.
> >
> > This strikes me as less portable - if I change my url mapping from Apache,
> > I'll have to edit my web.xml, which wouldn't have been necessary
> > before.  Is
> > this a bug, or has it really been changed to better comply with
> > the Servlet
> > spec?
> >
> > Best regards,
> >
> > Andy Eastham
> >
> >
> >
> > --
> > 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: Servlet Mapping Bug?

Posted by Andy Eastham <an...@gliant.com>.
This is a bug, as I've now checked the Servlet Specification v2.3:

The key phrase is:
The path used for mapping to a servlet is the request URL from the request
object minus the context path.
ie for my /control/plots/x.jpg request, the context path is /control, so
only /plots/x.jpg should be used to map the servlet.

I guess this bug is probably in the Coyote Connector?

Andy

PS
Here's the full text of the relevant bit from the servlet spec:

SRV.11.1 Use of URL Paths
Upon receipt of a client request, the web container determines the web
application to which to forward it. The web application selected must have
the longest context path that matches the start of the request URL.

The matched part of the URL is the context path when mapping to servlets.
The web container next must locate the servlet to process the request using
the path mapping procedure described below:
The path used for mapping to a servlet is the request URL from the request
object minus the context path. The URL path mapping rules below are used in
order. The first successful match is used with no further matches attempted:

1. The container will try to find an exact match of the path of the request
to the path of the servlet. A successful match selects the servlet.

2. The container will recursively try to match the longest path-prefix: This
is done by stepping down the path tree a directory at a time, using the '/'
character as a path separator. The longest match determines the servlet
selected.

3. If the last segment in the URL path contains an extension (e.g. .jsp),
the servlet
container will try to match a servlet that handles requests for the
extension.
An extension is defined as the part of the last segment after the last '.'
character.

4. If neither of the previous three rules result in a servlet match, the
container will
attempt to serve content appropriate for the resource requested. If a
"default"
servlet is defined for the application, it will be used.
The container must use case-sensitive string comparisons for matching.

Note 1. Previous versions of this specification made use of these mapping
techniques a suggestion rather than a requirement, allowing servlet
containers to each have their different schemes for mapping client requests
to servlets.

> -----Original Message-----
> From: Andy Eastham [mailto:andy.eastham@gliant.com]
> Sent: 14 January 2003 22:46
> To: Tomcat Users List
> Subject: Servlet Mapping Bug?
>
>
> Hi,
>
> I've just upgraded from Tomcat 4.0.4b1 and apache 1.3 using warp to Tomcat
> 4.1.18 and Apache 2.0.43 using mod_jk2.
>
> I use a feature of servlet mapping in web.xml, where I map any
> request under
> a particular directory to a single servlet.  My application is mapped from
> Apache under the url "/control/" and I invoke myServlet with any
> request to
> the "plots" subdirectory.  In the old configuration, the relevant
> part of my
> web.xml looked like:
>
>     <servlet-mapping>
>         <servlet-name>
>             myServlet
>         </servlet-name>
>         <url-pattern>
>             /plots/*
>         </url-pattern>
>     </servlet-mapping>
>
> However, in my new setup, I have had to change this to make it work:
>
>     <servlet-mapping>
>         <servlet-name>
>             myServlet
>         </servlet-name>
>         <url-pattern>
>             /control/plots/*
>         </url-pattern>
>     </servlet-mapping>
>
> ie put the full URI in the url-pattern, not just the path relative to the
> Tomcat application root.
>
> This strikes me as less portable - if I change my url mapping from Apache,
> I'll have to edit my web.xml, which wouldn't have been necessary
> before.  Is
> this a bug, or has it really been changed to better comply with
> the Servlet
> spec?
>
> Best regards,
>
> Andy Eastham
>
>
>
> --
> 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>


Servlet Mapping Bug?

Posted by Andy Eastham <an...@gliant.com>.
Hi,

I've just upgraded from Tomcat 4.0.4b1 and apache 1.3 using warp to Tomcat
4.1.18 and Apache 2.0.43 using mod_jk2.

I use a feature of servlet mapping in web.xml, where I map any request under
a particular directory to a single servlet.  My application is mapped from
Apache under the url "/control/" and I invoke myServlet with any request to
the "plots" subdirectory.  In the old configuration, the relevant part of my
web.xml looked like:

    <servlet-mapping>
        <servlet-name>
            myServlet
        </servlet-name>
        <url-pattern>
            /plots/*
        </url-pattern>
    </servlet-mapping>

However, in my new setup, I have had to change this to make it work:

    <servlet-mapping>
        <servlet-name>
            myServlet
        </servlet-name>
        <url-pattern>
            /control/plots/*
        </url-pattern>
    </servlet-mapping>

ie put the full URI in the url-pattern, not just the path relative to the
Tomcat application root.

This strikes me as less portable - if I change my url mapping from Apache,
I'll have to edit my web.xml, which wouldn't have been necessary before.  Is
this a bug, or has it really been changed to better comply with the Servlet
spec?

Best regards,

Andy Eastham



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


RE: jsp versus xml syntax

Posted by "Noel J. Bergman" <no...@devtech.com>.
> I wonder if we agree on something else as well :-).

> I feel that users who use variable declarations, function declarations,
> and scriptlets in JSP pages *at all* (no matter what syntax) are probably
> making a mistake.

It is however, useful for rapid prototyping, and in JSP v2 you can *and want
to* make use it in a more controlled fashion.  I am referring to JSP Tag
files (.tagf; see Chapter 8 of the JSP v2 Specification).

> Mixing Java code with JSP code is likely to lead to a
> morass of spaghetti that mixes business logic and
> presentation logic together, and will ultimately make
> maintenance much harder.

Using any flexible technology requires discipline.  But complicating early
development is also not optimal.  Struts, for example, is not the easiest
thing for new programmers.  Two of the benefits that JSP can provide in a
controller role are dynamic recompilation and integration between HTTP and
Java Bean components.  But you still want to keep your presentation and
model separate.

I think that JSP tag files will improve the overall developer experience
with Servlet/JSP technology.  We should see cleaner presentation pages
without losing the benefits of JSP.

And I know that you understand all of this, Craig.  You are one of the
Specification Leads for JavaServer Faces (JSR-127).  I realize that
JavaServer Faces is currently based upon JSP 1.2, but I am looking ahead to
how .tagf files can improve the experience for component developers.

	--- Noel


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


RE: jsp versus xml syntax

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

On Tue, 14 Jan 2003, Noel J. Bergman wrote:

> [snip]
> I happen to agree with Craig that it is a waste of time for a newbie to
> learn both syntaxes.  But it should be clear from my argument which syntax I
> consider appropriate for teaching.

I wonder if we agree on something else as well :-).

I feel that users who use variable declarations, function declarations,
and scriptlets in JSP pages *at all* (no matter what syntax) are probably
making a mistake.  Mixing Java code with JSP code is likely to lead to a
morass of spaghetti that mixes business logic and presentation logic
together, and will ultimately make maintenance much harder.

In JSP 1.x, there are legitimate needs for runtime expressions ("<%= ...
%>"), particularly in dynamically calculated attribute values for custom
tags.  That's the only embedding technology I *ever* use in a JSP page --
and the JSTL/JSP2 expression language virtually eliminates the need for
that as well, so I can confidently code my pages and never have to worry
about whether to say "<%! ... %>" or <jsp:declaration>" in the first
place.

>
> 	--- Noel

Craig


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


RE: jsp versus xml syntax

Posted by "Noel J. Bergman" <no...@devtech.com>.
> So for the record, what is allowed and what isn't?  Sorry that I am so
> confused about this.

JSP 1.0 and 1.1 were somewhat loose on the XML representation of JSP pages.

JSP 1.2 introduced a fully formal representation known as a JSP Document,
complete with jsp:root element, and explicitly says: "It is not valid,
however, to intermix standard JSP syntax and XML syntax inside the same
source file."  This resulted my arguing that:

"With JSP 1.2, [the page] must be either in <% syntax, or it must be a
completely proper [XML page.]  Since few people are going to code that by
hand, it means that people cannot use the clear, easy to remember,
self-describing, XML equivalent syntax.  This seems uncessarily restrictive
since JSP 1.2 otherwise mixes both XML and <% syntax.

I am not saying that people should be able to mix and match XML and <% on
the same page; the JSP specification says THAT for me.  Every JSP container
must support what I am asking for, except that JSP 1.2 ONLY supports it for
the standard actions and tag libraries, and removes support for
<jsp:scriptlet>, <jsp:directive>, <jsp:declaration> and <jsp:expression>.

Those, and specifically those, are what I am discussing.  All I am asking
for is that the use of the <jsp:xxx> equivalents be put on a syntactic peer
with the other <jsp:xxx> tags that are allowed in JSP 1.2 pages.  If I can
enter <jsp:useBean>, <%!, <%@, and <% on the same page, I ought to be able
to enter <jsp:useBean>, <jsp:declaration>, <jsp:directive>, and
<jsp:scriptlet> without penalty."

The JSP 2.0 draft specification says: "Some of the syntactic elements
described in Chapter 1 are not legal XML; this chapter describes alternative
syntaxes that are aligned with the XML syntax. The alternative syntaxes are
valid in *all* JSP pages"

The emphasis on "*all* JSP pages", and not just JSP Documents, is present as
bold face in the specification.  It is my understanding that it explicitly
addresses the issue raised above.  I certainly invite Craig to review that
section, and we can request clarification from Eduardo and Mark if
necessary.

I happen to agree with Craig that it is a waste of time for a newbie to
learn both syntaxes.  But it should be clear from my argument which syntax I
consider appropriate for teaching.

	--- Noel


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


Re: jsp versus xml syntax

Posted by Erik Price <ep...@ptc.com>.

Craig R. McClanahan wrote:

> To get the whole answer, you need to download and read the JSP spec.
> 
>   http://java.sun.com/products/jsp/download.html

That's on my to-read list, after the HTTP spec and the servlet spec.  I 
don't think it's going to happen overnight ;) .

> The short answer:  In JSP 1.x you cannot mix the two syntaxes -- period.
> Custom tags are expressed in "sort of" XML syntax (but without the
> standard namespace declarations.  If you use the XML syntax, you also need
> to be prepared to put CDATA blocks around all your code inside things like
> <jsp:expression>.

> I haven't reviewed what JSP 2.0 came up with as their final answer, but my
> recollection is that they were focused primarily on improving the
> usability of the XML syntax, but not on allowing mixing.  Need to review
> the Proposed Final Draft.
> 
> I stand by my statement that it's a waste of effort for a user (especially
> a newbie) to take the time to learn both syntaxes.

I'll take you up on this.  I have enough on my plate, and that makes 
sense that it's really designed for tools and not people.  I was just 
curious.  So in the end, I'm going to stick with JSP syntax except for 
custom tags and <jsp:useBean>.

Thanks again.


Erik



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


[Bonehead mistake of the week] web.xml issue?

Posted by Jason Pyeron <ja...@pyeron.com>.
So I was about to put together a very big posting with conf files and then 
I realized after a week of debuging, Tomcat did not have read permission 
on the tld file.

-jp

I am trying to use the JSTL, but some where I have an error in my web.xml 
or tld file. When starting the context I get this:

2003-01-14 12:58:12 ContextConfig[] Exception processing TLD at resource path /WEB-INF/tld/c-rt.tld
javax.servlet.ServletException: Exception processing TLD at resource path /WEB-INF/tld/c-rt.tld
        at ...
----- Root Cause -----
java.lang.IllegalArgumentException: Invalid TLD resource path /WEB-INF/tld/c-rt.tld
        at ...





-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                   http://www.pyerotechnics.com   -
- Owner & Lead                  Pyerotechnics Development, Inc. -
- +1 410 808 6646 (c)           500 West University Parkway #1S -
- +1 410 467 2266 (f)           Baltimore, Maryland  21210-3253 -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

This message is for the designated recipient only and may contain 
privileged, proprietary, or otherwise private information. If you
have received it in error, purge the message from your system and 
notify the sender immediately.  Any other use of the email by you 
is prohibited.




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


Re: jsp versus xml syntax

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

On Tue, 14 Jan 2003, Erik Price wrote:

> Date: Tue, 14 Jan 2003 10:11:32 -0500
> From: Erik Price <ep...@ptc.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: jsp versus xml syntax
>
>
>
> Noel J. Bergman wrote:
> >>Do yourself a favor and skip learning the XML syntax.  It's for tools, not
> >>people.
> >
> >
> > Oh, I would argue that considerably.  In fact I did.  That is no longer true
> > in JSP v2.0.
> >
> > It is absolutely an absurdity to treat <jsp:action|custom-tag> differently
> > from <jsp:expression|declaration|scriptlet|directive>.  It is also also
> > ridiculous to require users to remember which obscure character (@%!=) means
> > what behavior.
> >
> > That is the short version.  The argument presented to Sun a year or so back
> > was considerably longer.
>
> So then what is the deal?  A former post had me finally nodding my head
> in understanding that in JSPs, "use only JSP syntax, because you can't
> mix the two" but then this one raises the good point that "aren't
> <jsp:useBean> tags and custom tags XML syntax?" and they are allowed.
>
> So for the record, what is allowed and what isn't?  Sorry that I am so
> confused about this.
>

To get the whole answer, you need to download and read the JSP spec.

  http://java.sun.com/products/jsp/download.html

The short answer:  In JSP 1.x you cannot mix the two syntaxes -- period.
Custom tags are expressed in "sort of" XML syntax (but without the
standard namespace declarations.  If you use the XML syntax, you also need
to be prepared to put CDATA blocks around all your code inside things like
<jsp:expression>.

I haven't reviewed what JSP 2.0 came up with as their final answer, but my
recollection is that they were focused primarily on improving the
usability of the XML syntax, but not on allowing mixing.  Need to review
the Proposed Final Draft.

I stand by my statement that it's a waste of effort for a user (especially
a newbie) to take the time to learn both syntaxes.

>
> Thanks
>
>
> Erik

Craig


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


Re: jsp versus xml syntax

Posted by Erik Price <ep...@ptc.com>.

Noel J. Bergman wrote:
>>Do yourself a favor and skip learning the XML syntax.  It's for tools, not
>>people.
> 
> 
> Oh, I would argue that considerably.  In fact I did.  That is no longer true
> in JSP v2.0.
> 
> It is absolutely an absurdity to treat <jsp:action|custom-tag> differently
> from <jsp:expression|declaration|scriptlet|directive>.  It is also also
> ridiculous to require users to remember which obscure character (@%!=) means
> what behavior.
> 
> That is the short version.  The argument presented to Sun a year or so back
> was considerably longer.

So then what is the deal?  A former post had me finally nodding my head 
in understanding that in JSPs, "use only JSP syntax, because you can't 
mix the two" but then this one raises the good point that "aren't 
<jsp:useBean> tags and custom tags XML syntax?" and they are allowed.

So for the record, what is allowed and what isn't?  Sorry that I am so 
confused about this.


Thanks


Erik


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


RE: jsp versus xml syntax

Posted by "Noel J. Bergman" <no...@devtech.com>.
> Do yourself a favor and skip learning the XML syntax.  It's for tools, not
> people.

Oh, I would argue that considerably.  In fact I did.  That is no longer true
in JSP v2.0.

It is absolutely an absurdity to treat <jsp:action|custom-tag> differently
from <jsp:expression|declaration|scriptlet|directive>.  It is also also
ridiculous to require users to remember which obscure character (@%!=) means
what behavior.

That is the short version.  The argument presented to Sun a year or so back
was considerably longer.

	--- Noel


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


Re: jsp versus xml syntax

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

On Mon, 13 Jan 2003, Jeff Ousley wrote:

> Date: Mon, 13 Jan 2003 10:49:51 -0800 (PST)
> From: Jeff Ousley <je...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: jsp versus xml syntax
>
> Hello!
>
> I'm using (learning) tomcat-4.1.18 and I'm trying to
> get the following example page to work:
>
>

Do yourself a favor and skip learning the XML syntax.  It's for tools, not
people.

Craig


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