在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>
在JavaConfig中
public class WebInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext)
throws ServletException {
// ??
}
}
如何在JavaConfig上设置jsp-config?
最佳答案
该代码应该工作:
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起,最后一条语句将可用