Skip to content

Commit b088f60

Browse files
author
Dave Syer
committed
Investigated JSP support
Summary: Tomcat works with WARs. Jetty doesn't work. See spring-projectsgh-367
1 parent da26c61 commit b088f60

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

spring-boot/README.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -249,29 +249,22 @@ can also register items directly if your bean implements the `ServletContextInit
249249
interface.
250250

251251

252-
### JSP limitations
253-
When running a Spring Boot application that uses an embedded servlet container and is
254-
packaged as an executable JAR or WAR, there are some limitations in the JSP support.
255-
256-
Due to the way that Jasper (Tomcat and Jetty's JSP engine) loads tag libraries, tag
257-
libraries packaged in JAR files nested within the JAR or WAR will not work correctly.
258-
When packaged and run as an executable JAR, you will see an error message produced during
259-
application startup that is similar to the following:
260-
261-
> org.apache.jasper.JasperException: The absolute uri: http://www.springframework.org/tags
262-
> cannot be resolved in either web.xml or the jar files deployed with this application
263-
264-
When packaged and run as an executable WAR, you will see an error message produced during
265-
application startup that is similar to the following:
266-
267-
> java.io.FileNotFoundException: JAR entry
268-
> WEB-INF/lib-provided/tomcat-embed-jasper-7.0.47.jar!/javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd
269-
> not found in my-app.war
270-
271-
To avoid these limitations, rather than using the embedded servlet container support,
272-
package your application as a traditional (non-executable) WAR file and deploy it to a
273-
servlet container. Alternatively, you may want to consider using an alternative view
274-
technology.
252+
### JSP limitations When running a Spring Boot application that uses
253+
an embedded servlet container and is packaged as an executable
254+
archive, there are some limitations in the JSP support.
255+
256+
* With Tomcat it should work if you use WAR packaging. I.e. an
257+
executable WAR will work, and will also be deployable to a standard
258+
container (Tomcat included). An executable JAR will not work because
259+
of a hard coded file patter in Tomcat itself.
260+
261+
* Jetty does not currently work as an embedded container with
262+
JSPs. There should be a way to make it work, so hopefully someone
263+
can figure it out (pull requests always welcome).
264+
265+
There is a
266+
[JSP sample](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp)
267+
so you can see how to set things up.
275268

276269
## Using YAML instead of Properties
277270
[YAML](http://yaml.org) is a superset of JSON, and as such is a very convenient format

spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ protected final File getValidDocumentRoot() {
304304
// Or maybe there is a document root in a well-known location
305305
file = file != null ? file : getCommonDocumentRoot();
306306
if (file == null && this.logger.isWarnEnabled()) {
307-
this.logger.debug("None of the document roots "
307+
this.logger.info("None of the document roots "
308308
+ Arrays.asList(COMMON_DOC_ROOTS)
309309
+ " point to a directory and will be ignored.");
310310
}
@@ -340,7 +340,11 @@ private File getArchiveFileDocumentRoot(String extension) {
340340
}
341341

342342
private File getWarFileDocumentRoot() {
343-
return getArchiveFileDocumentRoot(".war");
343+
File file = getArchiveFileDocumentRoot(".war");
344+
if (file != null) {
345+
return file;
346+
}
347+
return getArchiveFileDocumentRoot(".jar");
344348
}
345349

346350
private File getCommonDocumentRoot() {

spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ private void configureDocumentRoot(WebAppContext handler) {
131131
File root = getValidDocumentRoot();
132132
if (root != null) {
133133
try {
134-
handler.setBaseResource(Resource.newResource(root));
134+
if (!root.isDirectory()) {
135+
handler.setBaseResource(Resource.newClassPathResource(""));
136+
}
137+
else {
138+
handler.setBaseResource(Resource.newResource(root));
139+
}
135140
}
136141
catch (Exception ex) {
137142
throw new IllegalStateException(ex);

0 commit comments

Comments
 (0)