OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.15k stars 592 forks source link

JSP compilation settings not honored? #12593

Open mthmulders opened 4 years ago

mthmulders commented 4 years ago

Describe the bug This issue is a follow-up on https://github.com/OpenLiberty/ci.maven/issues/838.

I'm trying to have OpenLiberty compile my JSP files on startup through the Maven goal, but that didn't work. @cherylking suggested to try it without that Maven goal by setting <jspEngine prepareJsps="0" /> and <webContainer deferServletLoad="false" /> in server.xml, but that didn't work either.

Steps to Reproduce

Take a sample application and add the following to server.xml:

<jspEngine prepareJsps="0" scratchdir="./scratch-dir" jdkSourceLevel="18" />
<webContainer deferServletLoad="false" />

Start the application using mvn liberty:dev.

Expected behavior I would expect the designated scratchdir to contain class files for the JSP files in my application. This does not happen when I start the application. When I access it (with a web browser), those files appear. Since deferServletLoad is false I would expect it to happen when the application starts, not when it is accessed.

Diagnostic information:

cherylking commented 4 years ago

I think the sample application link should be this: https://github.com/mthmulders/openliberty-mvc/

epj commented 4 years ago

I suspect the precompile isn't working because your jsp files are under WEB-INF, which isn't a public location for webapp files. Can you try moving them out from under WEB-INF and see if precompile then finds them?

mthmulders commented 4 years ago

You're right, @epj. When I move the JSP files to src/main/webapp, they're immediately compiled when the server starts. I wasn't aware of the requirement that they may not reside under WEB-INF.

OTOH, I feel it's not uncommon to store JSP files there, especially with frameworks like Struts, Spring Web or Krazo. I think the idea is that the user cannot invoke those views directly, if they'd know the path to the file, but only through those MVC-style frameworks.

hearit-danny commented 2 years ago

Any update on this? I understand that the workaround is to move JSP files to src/main/webapp, but the JEE spec says that JSPs should be in the WEB-INF folder if you don't want them publically available.

There are situations where you want to install a WAR on a liberty server but you don't control how that WAR is is built where there are JSPs in WEB-INF folders per the convention above, and the JSP feature seems to miss them. Any change the JSP feature can support compiling JSPs from a WEB-INF location?

epj commented 2 years ago

As long as you access a JSP file through an indirect means, such as it can be under WEB-INF. Same for includes or fragments (jspf files). However, any JSP that will be called directly can not be under WEB-INF. The precompile option just assumes that any jsp in an app outside of WEB-INF are callable and precompiled. No provision to look under WEB-INF for precompile candidates, sorry.