<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>
JavaConfig中的
public class WebInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext)
throws ServletException {
// ??
}
}
如何在JavaConfig上设置jsp-config?
答案 0 :(得分:0)
您可以使用
访问它servletContext.getJspConfigDescriptor().getJspPropertyGroups();
返回有{。}的
Collection<JspPropertyGroupDescriptor>
add(JspPropertyGroupDescriptor)
方法。JspPropertyGroupDescriptor
是 你必须实现的接口。你可能会更好 具有部分web.xml
和部分java配置。
答案 1 :(得分:0)
此代码应该有效:
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);
但是自Tomcat 8以来,最后一条声明将可用