The JSP specification allows me to serve .html
files as JSP (that is, have the container process them as JSP files) using a <jsp-config>
section in web.xml
, e.g.:
<web-app …>
<jsp-config>
<jsp-property-group>
<url-pattern>*.html</url-pattern>
</jsp-property-group>
</jsp-config>
</web-app>
But when I switch to running a @SpringBootApplication
with embedded Tomcat, it completely bypasses the web.xml
file. Is there an equivalent setting in Spring Boot MVC to set the JSP configuration of a JSP property group, as per standard web.xml
, that will configure the existing embedded Tomcat JSP servlet?
(Another example of a JSP setting I might want to configure is <trim-directive-whitespaces>
.)
Before you mark this as a duplicate, please read this closely. I am aware of the extensive answer by walkeros. But that answer only considers adding a new JSP servlet. It does not address adding a new JSP property group to the existing JSP servlet, and indeed doesn't mention the <jsp-config>
section in web.xml
at all.
Application Configuration xml file as a deployment descriptor file. Also, it defines mappings between URL paths and the servlets in the web. xml file. This is no longer the case with Spring Boot.
Spring allows you to configure your beans using Java and XML.
xml under the WebContent/WEB-INF folder.
When building Web Applications, JavaServer Pages (JSP) is one option we can use as a templating mechanism for our HTML pages. On the other hand, Spring Boot is a popular framework we can use to bootstrap our Web Application.
You may find a way to make Spring Boot work with XML configurations, but that is not the way it is supposed to be. To apply special JSP configurations to your application, you could do that as follows:
public class MyJspConfigDescriptor implements JspConfigDescriptor {
private Collection<JspPropertyGroupDescriptor> jspPropertyGroups =
new LinkedHashSet<JspPropertyGroupDescriptor>();
private Collection<TaglibDescriptor> taglibs =
new HashSet<TaglibDescriptor>();
@Override
public Collection<JspPropertyGroupDescriptor> getJspPropertyGroups() {
JspPropertyGroup newPropertyGroup = new JspPropertyGroup();
newPropertyGroup.addUrlPattern("*.html");
// You can add more configurations as you wish!
JspPropertyGroupDescriptorImpl jspDescriptor = new JspPropertyGroupDescriptorImpl(newPropertyGroup);
jspPropertyGroups.add(jspDescriptor);
return jspPropertyGroups;
}
@Override
public Collection<TaglibDescriptor> getTaglibs() {
return taglibs;
}
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.getJspConfigDescriptor().getJspPropertyGroups().addAll((new MyJspConfigDescriptor()).getJspPropertyGroups());
}
I believe that this would work, but I didn't really test it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With