Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring webmvc is not compatible with tomcat-embed-jasper for a JSP project #34351

Closed
jithin1009 opened this issue Feb 1, 2025 · 3 comments
Closed
Labels
for: stackoverflow A question that's better suited to stackoverflow.com in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@jithin1009
Copy link

jithin1009 commented Feb 1, 2025

When JSP files consist of multiple includes of other JSPa, ResourceHttpMessageConverter is unable to writeContent.

From my initial analysis, HttpOutputMessage is a ServletResponseWrapperInclude of tomcat jasper, which will throw an IllegalArgumentException when trying to access the outputStream.

See the below stack trace for more details

java.lang.IllegalStateException: null
	at org.apache.jasper.runtime.ServletResponseWrapperInclude.getOutputStream(ServletResponseWrapperInclude.java:64)
	at org.springframework.http.server.ServletServerHttpResponse.getBody(ServletServerHttpResponse.java:98)
	at org.springframework.http.converter.ResourceHttpMessageConverter.writeContent(ResourceHttpMessageConverter.java:159)
	at org.springframework.http.converter.ResourceHttpMessageConverter.writeInternal(ResourceHttpMessageConverter.java:115)
	at org.springframework.http.converter.ResourceHttpMessageConverter.writeInternal(ResourceHttpMessageConverter.java:46)
	at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:235)
	at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:621)
	at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:52)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:632)
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:510)
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:453)
	at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:994)

Is there any other way to bypass this?

@jithin1009 jithin1009 changed the title Spring web is not compatible with tomcat-embed-jasper for a JSP project Spring webmvc is not compatible with tomcat-embed-jasper for a JSP project Feb 1, 2025
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 1, 2025
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Feb 1, 2025
@bclozel
Copy link
Member

bclozel commented Feb 1, 2025

Is there a problem with your setup? I find a bit ususual that a JSP would be served as a static resource. Can you share a minimal sample that reproduces the problem?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Feb 1, 2025
@jithin1009
Copy link
Author

We believe our setup is correct. Our code will return text/javascript as a response and this response is sent to another component

`<%@ page language="java"%>
<%@ page import="java.net.URLDecoder" %>
<jsp:include page='/static/v_1_0/scripts/jquery-1.11.0.min.js'/>

`

in the above Jsp if we remove the last include everything is working fine.

My Observations

in ServeltServerHttpResponse class

@Override public OutputStream getBody() throws IOException { this.bodyUsed = true; writeHeaders(); return this.servletResponse.getOutputStream(); }
In the above code, getOutputStream will throw IllegalArgumentException

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 1, 2025
@bclozel
Copy link
Member

bclozel commented Feb 1, 2025

This is invalid.

"jsp:include page" is meant for including dynamic JSP pages, not static files served by Spring.

If you need more help please ask a question on StackOverflow.

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2025
@bclozel bclozel added status: invalid An issue that we don't feel is valid for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants