4

in web.xml

<jsp-config>
    <jsp-property-group>
        <description> </description>
        <display-name>JSPConfiguration</display-name>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>EUC-KR</page-encoding>  
    </jsp-property-group>
</jsp-config>

in JavaConfig

public class WebInitializer implements WebApplicationInitializer {

    public void onStartup(ServletContext servletContext)
            throws ServletException {
        //  ??
        }
}

How to setup jsp-config at JavaConfig?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
takeone
  • 43
  • 1
  • 4
  • You have access to it with `servletContext.getJspConfigDescriptor().getJspPropertyGroups();` returning a `Collection` which has an `add(JspPropertyGroupDescriptor)` method. `JspPropertyGroupDescriptor` is an interface which you have to implement. You're probably better off having a partial web.xml and partial java configuration. – Sotirios Delimanolis Apr 24 '13 at 16:07

2 Answers2

0

You have access to it with

servletContext.getJspConfigDescriptor().getJspPropertyGroups();

returning a Collection<JspPropertyGroupDescriptor> which has an add(JspPropertyGroupDescriptor) method. JspPropertyGroupDescriptor is an interface which you have to implement. You're probably better off having a partial web.xml and partial java configuration.

Sotirios Delimanolis Apr 24 at 16:07

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
0

this code should work:

    JspConfigDescriptor j = new JspConfigDescriptor()
    {

        @Override
        public Collection<TaglibDescriptor> getTaglibs()
        {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Collection<JspPropertyGroupDescriptor> getJspPropertyGroups()
        {
            Collection<JspPropertyGroupDescriptor> c = new ArrayList<JspPropertyGroupDescriptor>();
            JspPropertyGroupDescriptorImpl pgDescriptor = new JspPropertyGroupDescriptorImpl();
            pgDescriptor.setIsXml(Boolean.TRUE.toString());
            pgDescriptor.getUrlPattern().add("/js/generated/*");
            pgDescriptor.setElIgnored(Boolean.FALSE.toString());
            pgDescriptor.setPageEncoding("UTF-8");
            c.add(pgDescriptor);
            return null;
        }
    };
    servletContext.setJspConfigDescriptor(j);

But last statement will be available since Tomcat 8

  • 1
    Can you extend your example a bit? the ServletContext does not seem to have the setJspConfigDescriptor method, at least not in the tomcat-embed-core-8.0.5.jar – maxb May 08 '14 at 12:54
  • does not have setJspConfigDescriptor in tomcat-embed-core-8.0.23.jar@javax.servlet.ServletContext or javax.servlet-api-3.1.0.jar@javax.servlet.ServletContext ... – olivervbk Jul 09 '15 at 19:39
  • @maxb To write JSP settings, one need to access the JSP engine implementation, or continue using web.xml. In the code snippet in this answer `servletContext` is `org.apache.catalina.Context`, not `javax.servlet.ServletContext`. See https://stackoverflow.com/a/59344649/156973 – izogfif Jun 11 '21 at 15:53