Assuming you only have one Tomcat service with one connector, you can access it in Servlet:
int maxPostSize = ServerFactory.getServer().findServices()[0].findConnectors()[0].getMaxPostSize();
ServerFactory , by the way, org.apache.catlina.ServerFactory .
Note. This is closely related to your code with the Tomcat servlet server, and your webapp cannot be reused in other servlet containers, perhaps even in different versions. Consider setting your own context parameter in web.xml with the same value.
<context-param> <param-name>maxPostSize</param-name> <param-value>2097152</param-value> </context-param>
Then you can access it in Servlet with
int maxPostSize = Integer.valueOf(getServletContext().getInitParameter("maxPostSize"));
or in jsp
${initParam.maxPostSize}
Balusc
source share