You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Richárd Olivér Legéndi <ri...@gmail.com> on 2018/01/24 21:31:53 UTC

Modify JspServlet config in application web.xml?

Hi All,

Yaaaay! I'm sending a tech mail to an open source community after years!
You can't believe what a relief it is :-)

Anyaway, I would like to ask your help about some config topic.

I would need the following configuration *only *for my webapp:

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
        <param-name>mappedfile</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>trimSpaces</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup></servlet>

So far I thought this is a setting which is global for Tomcat (i.e., it can
only be configured in Tomcat's *web.xml*). This is something I am not
allowed to do, beceause the Tomcat has other apps too.

I have made some experiments and for me it seems when I run the app locally
on my developer machine these settings take place even when it is only in
the *web.xml* of my own application.

Could someone enlighten me what is the exact mechanism here?

The docs <http://www2.hu-berlin.de/newlogic/docs/jasper-howto.html> also
say *"The servlet which implements Jasper is configured using init
parameters in your global $CATALINA_BASE/conf/web.xml"* so I'm confused if
this is an expected behaviour, only a "developer setting" or it could work
in a more restrictive production environment too. What I can think of is
that the servlet generator has different contexts for all the applications,
and if there is no specific setting then it inherits the one defined in the
global *web.xml*.

Any links / pointers / suggestions would be more than welcome!

Thanks a lot in advance, guys!

Best,
Richard

Re: Modify JspServlet config in application web.xml?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Richárd,

On 1/27/18 7:18 AM, Richárd Olivér Legéndi wrote:
> Thanks a lot, Christopher and Mark!
> 
> Wow, lot of knowledge and pointers to move forward. I've debugged a
> bit around both ContextConfig and JspServlet, and it is exactly as
> you described. This saves a hell lot of work for me and helps avoid
> some stressful meetings :D
> 
> Thanks a lot! Also for the reference of the Servlet spec, I think
> it's time to go through it.

It's one of the most readable spec documents I've ever read. Well
worth the read for anyone who will be doing anything web-related with
Java EE.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlpt/SwACgkQHPApP6U8
pFh8mRAAgvJLHaZmWe6640lbYHiKrkzW8pr9SF3F/JLZI1VsSJGQYJLqSfHeWETs
BCjyKibw/9x/iIq9WbLUA5W1liUMnp0o0kvj7U+zbYrTmqqpcfy8aoFstbfjVrVz
mdrloK0qgtrFjGyx0Z8aWOnuDd5DvNJPDv0GVPia50+zX3xWD63/w7RuqVqeoKOM
GF3q2G1AZ1COagnPMdYf6T/vMFVoS5YnllSowDYPbxEUt8bvqdXjllbDKZhTrgON
CUDaqIsfyCRcw5MpSh0tfkktC0SSL3iVsj0GGU8XNb2akDpu4Cd8k1GLyeLZfqJm
G9WFVU1ckiGlyDcnGOGKQtinMKLmf2EwwlK84pc2q7y7DCzWn18Vq0HiKBRA4sNf
yQJtLHsumhhIyl05Pv1WHnmlJiqUYoD8i9JX8RmVFjV79q2j7jVvBDa9Rpkblgxz
DwTkPkOY77h0JL7+VmjKkTG+NF8Xua9w6Fbq1Hf6P2ufxnm44xA9zB8kpPvVyLcC
dJZ6QTvAfUkw7eA6y2X+ixxZ4RGWlLxSNC/X7aySiMVuS++IhDieAA5TRkbwZC1v
OwayUOWFjtqSAdP50t3xMJwanv2bH55PD6wSoh+vLsPYZyfdMeqj4YCIcPgTHQbD
sGpnZZ3/P6Pz/Yj5V6zAtJrYIg2rUQ0oV2rR8CTH2zdmbzq7FXs=
=S0xs
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Modify JspServlet config in application web.xml?

Posted by Richárd Olivér Legéndi <ri...@gmail.com>.
Thanks a lot, Christopher and Mark!

Wow, lot of knowledge and pointers to move forward. I've debugged a bit
around both ContextConfig and JspServlet, and it is exactly as you
described. This saves a hell lot of work for me and helps avoid some
stressful meetings :D

Thanks a lot! Also for the reference of the Servlet spec, I think it's time
to go through it.

Have a nice weekend, guys!

Best,
Richard


On 25 January 2018 at 11:33, Mark Thomas <ma...@apache.org> wrote:

> On 25/01/18 05:25, Christopher Schultz wrote:
>
> <snip/>
>
> > You can also use <init-param> in WEB-INF/web.xml for the JSP servlet.
> > You will probably have to copy those settings you want from the JSP
> > configuration in conf/web.xml because I don't think Tomcat will merge
> > init-param between the two files.
>
> Tomcat should merge the init-param entries. The rules for merging the
> default web.xml file are as follows.
>
> 1. Web fragments, annotations etc. are merged into the main web.xml as
> per the Servlet spec merge rules to created an updated main web.xml.
>
> 2. The default web.xml is them merged into the updated main web.xml as
> if the default web.xml was a web fragment again following the Servlet
> spec rules with one exception. If there is a conflict, rather than
> triggering an error, the updated main web.xml always takes precedence.
>
> The code that does this is in ContextConfig and WebXml.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Modify JspServlet config in application web.xml?

Posted by Mark Thomas <ma...@apache.org>.
On 25/01/18 05:25, Christopher Schultz wrote:

<snip/>

> You can also use <init-param> in WEB-INF/web.xml for the JSP servlet.
> You will probably have to copy those settings you want from the JSP
> configuration in conf/web.xml because I don't think Tomcat will merge
> init-param between the two files.

Tomcat should merge the init-param entries. The rules for merging the
default web.xml file are as follows.

1. Web fragments, annotations etc. are merged into the main web.xml as
per the Servlet spec merge rules to created an updated main web.xml.

2. The default web.xml is them merged into the updated main web.xml as
if the default web.xml was a web fragment again following the Servlet
spec rules with one exception. If there is a conflict, rather than
triggering an error, the updated main web.xml always takes precedence.

The code that does this is in ContextConfig and WebXml.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Modify JspServlet config in application web.xml?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Richárd,

On 1/24/18 4:31 PM, Richárd Olivér Legéndi wrote:
> Yaaaay! I'm sending a tech mail to an open source community after
> years! You can't believe what a relief it is :-)

Welcome to the community!

> Anyway, I would like to ask your help about some config topic.
> 
> I would need the following configuration *only *for my webapp:
> 
> <servlet> <servlet-name>jsp</servlet-name> 
> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
>
> 
<init-param>
> <param-name>mappedfile</param-name> 
> <param-value>false</param-value> </init-param> <init-param> 
> <param-name>trimSpaces</param-name> 
> <param-value>true</param-value> </init-param> 
> <load-on-startup>3</load-on-startup></servlet>
> 
> So far I thought this is a setting which is global for Tomcat
> (i.e., it can only be configured in Tomcat's *web.xml*). This is
> something I am not allowed to do, because the Tomcat has other apps
> too.
> 
> I have made some experiments and for me it seems when I run the app
> locally on my developer machine these settings take place even when
> it is only in the *web.xml* of my own application.
> 
> Could someone enlighten me what is the exact mechanism here?

When Tomcat deploys your context ("webapp"), it merges the global
conf/web.xml and the application's WEB-INF/web.xml with the
application's configuration overriding anything in the global
configuration. Therefore, if you replace the "jsp" servlet
configuration in WEB-INF/web.xml, it will (a) work and (b) only affect
that single application.

> The docs <http://www2.hu-berlin.de/newlogic/docs/jasper-howto.html>
> also say *"The servlet which implements Jasper is configured using
> init parameters in your global $CATALINA_BASE/conf/web.xml"* so I'm
> confused if this is an expected behaviour, only a "developer
> setting" or it could work in a more restrictive production
> environment too. What I can think of is that the servlet generator
> has different contexts for all the applications, and if there is no
> specific setting then it inherits the one defined in the global
> *web.xml*.

You can also use <init-param> in WEB-INF/web.xml for the JSP servlet.
You will probably have to copy those settings you want from the JSP
configuration in conf/web.xml because I don't think Tomcat will merge
init-param between the two files.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlppajUACgkQHPApP6U8
pFjeyw//Zg07qWt1IJV9i2UvEJqkd7fcWXo/1XMwIvJPKXSBYU6r4HzSw5o8O2WQ
SNDpFhGE08YLTVQ86h8rQk9CgT1xLbuFcJixuxC/CoLB4MfiECpVZJyDukilt9j6
JUgGOEAmxmqetkb9y/5dkUe34KxjNC1nTx3MQTSCw3vCk2W4JL8WT1w/XU1XOGtB
mgtZm8eu5WQU1baUkUN5du35TxnpXSJ51PnI9XWEhto3gZ0PvPNKSnqYK1OMJPn7
FBGDrTv050+OocIDC4TPyh+V0zt3f67zvyYk4SIwDXE++9dJ0UYtjnS2zzlerAug
F5PUhbWYBdMUivirGP8wZ3cfRGxzvXRnZA29+u6e57PaCTBeec2C/oc8pyuBSlkD
dQVgc9/MdrVm+I1ukfYwiuQwD7NEUNAPe83e/lQerpJQ5MwWlMtH9EI0Tdo1c6AC
JwYgDRICvDhdBhJS6JrbrsmAbT3TAgHxoCTduktFHKsqPj5Ujc+9+4C9sU9PB1Ch
3/CoXT1H0pEZkxeCOK6C+J7pIOvO5tPOmu1z9BpVc80q9YXkjrJCGLWAhj82iCrA
KoKHhPQpp4AoviUBO+Gi/cBh18OOLeyIb4UIza+lec64OERerIgHqZo7HX4Z/cT5
LbG1mquwAdpIzjIWCYvoTRgsepZCwu0WgV2xYcP6YvP4/6NJ+Dg=
=uEFM
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org