【问题标题】:Programmatic Servlet 3.0 JSP jsp-property-group configuration程序化 Servlet 3.0 JSP jsp-property-group 配置
【发布时间】:2015-03-26 21:50:12
【问题描述】:

我能够在我的ServletContainerInitializer 中创建 servlet 和过滤器,但是是否可以将旧的 web.xml 的最后剩余部分转换为 Servlet 3.0 编程配置?

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
        <trim-directive-whitespaces>true</trim-directive-whitespaces>
    </jsp-property-group>
</jsp-config>

【问题讨论】:

  • 没人会回答吗?你是怎么处理的?
  • 我在 3.1 中使用这个 - 没问题...

标签: java jakarta-ee servlet-3.0


【解决方案1】:

Servlet 3.x 仅为 JSP 设置指定读取接口。

编写 JSP 设置,需要访问JSP 引擎实现,或者继续使用web.xml。后者不是大问题,因为web.xml 可以与ServletContainerInitializer 安全共存。所以建议保留web.xml

然而,这是 Spring Boot 的一个问题,它忽略了web.xml

使用带有嵌入式 TomcatSpring Boot 2 可以使用 TomcatContextCustomizer 来实现:

@Component
public class JspConfig implements TomcatContextCustomizer {
    @Override
    public void customize(Context context) {
        JspPropertyGroup pg = new JspPropertyGroup();
        pg.addUrlPattern("/*");
        pg.setPageEncoding("UTF-8");
        pg.setTrimWhitespace("true");
        ArrayList<JspPropertyGroupDescriptor> pgs = new ArrayList<>();
        pgs.add(new JspPropertyGroupDescriptorImpl(pg));
        context.setJspConfigDescriptor(new JspConfigDescriptorImpl(pgs, new ArrayList<TaglibDescriptor>()));
    }
}

【讨论】:

    猜你喜欢
    • 2012-03-26
    • 2016-02-01
    • 2014-01-10
    • 2015-01-22
    • 2014-04-13
    • 1970-01-01
    • 2012-01-16
    • 2012-04-20
    • 2010-11-01
    相关资源
    最近更新 更多