Skip to content

Commit 511a7a5

Browse files
committed
完善 solon-server-jetty-jakarta jsp 适配
1 parent 20d9c55 commit 511a7a5

File tree

7 files changed

+21
-26
lines changed

7 files changed

+21
-26
lines changed

solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/main/java/org/noear/solon/boot/jetty/JettyServerAddJsp.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.eclipse.jetty.ee11.jsp.JettyJspServlet;
1919
import org.eclipse.jetty.ee11.servlet.ServletContextHandler;
2020
import org.eclipse.jetty.ee11.servlet.ServletHolder;
21-
import org.noear.solon.boot.jetty.http.JtJspStarter;
21+
import org.noear.solon.boot.jetty.jsp.JspLifeCycle;
2222
import org.noear.solon.boot.jetty.jsp.JspTldLocator;
2323

2424
import jakarta.servlet.ServletContext;
@@ -37,13 +37,13 @@ public class JettyServerAddJsp extends JettyServer {
3737
protected ServletContextHandler buildHandler() throws IOException {
3838
ServletContextHandler handler = getServletHandler();
3939

40-
enableJspSupport(handler);
40+
addJspSupport(handler);
4141
addTdlSupport(handler.getServletContext());
4242

4343
return handler;
4444
}
4545

46-
private void enableJspSupport(ServletContextHandler handler) throws IOException {
46+
private void addJspSupport(ServletContextHandler handler) throws IOException {
4747

4848
// Set Classloader of Context to be sane (needed for JSTL)
4949
// JSP requires a non-System classloader, this simply wraps the
@@ -53,7 +53,7 @@ private void enableJspSupport(ServletContextHandler handler) throws IOException
5353
handler.setClassLoader(jspClassLoader);
5454

5555
// Manually call JettyJasperInitializer on context startup
56-
handler.addBean(new JtJspStarter(handler));
56+
handler.addBean(new JspLifeCycle(handler));
5757

5858
// Create / Register JSP Servlet (must be named "jsp" per spec)
5959
ServletHolder holderJsp = new ServletHolder("jsp", JettyJspServlet.class);
@@ -63,7 +63,7 @@ private void enableJspSupport(ServletContextHandler handler) throws IOException
6363
}
6464

6565
private void addTdlSupport(ServletContext servletContext) throws IOException {
66-
Map<String, TaglibDescriptor> tagLibInfos = JspTldLocator.createTldInfos("templates");
66+
Map<String, TaglibDescriptor> tagLibInfos = JspTldLocator.createTldInfos("WEB-INF", "templates");
6767

6868
if (tagLibInfos.size() > 0) {
6969
ServletContextHandler.JspConfig jspConfig = (ServletContextHandler.JspConfig) servletContext.getJspConfigDescriptor();

solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/main/java/org/noear/solon/boot/jetty/JettyServerBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected ServerConnector getConnector(Server server, String host, int port, boo
157157
}
158158

159159
protected ServletContextHandler getServletHandler() throws IOException {
160-
_tempdir = System.getenv("java.io.tmpdir");
160+
_tempdir = System.getProperty("java.io.tmpdir");
161161
_fileOutputBuffer = 1 * 1024 * 1024;
162162
_maxBodySize = (ServerProps.request_maxBodySize > 0 ? ServerProps.request_maxBodySize : -1L);
163163
_maxFileSize = (ServerProps.request_maxFileSize > 0 ? ServerProps.request_maxFileSize : -1L);
@@ -192,14 +192,14 @@ protected ServletContextHandler getServletHandler() throws IOException {
192192

193193
//添加临时文件(用于jsp编译,或文件上传)
194194
File tempDir = new File(System.getProperty("java.io.tmpdir"));
195-
File scratchDir = new File(tempDir.toString(), "solon.boot.jetty");
195+
File scratchDir = new File(tempDir.toString(), "solon.server.jetty");
196196

197197
if (!scratchDir.exists()) {
198198
if (!scratchDir.mkdirs()) {
199199
throw new IOException("Unable to create scratch directory: " + scratchDir);
200200
}
201201
}
202-
handler.setAttribute("javax.servlet.context.tempdir", scratchDir);
202+
handler.setAttribute("jakarta.servlet.context.tempdir", scratchDir);
203203

204204
return handler;
205205
}

solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/main/java/org/noear/solon/boot/jetty/http/JtHttpContextServletHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class JtHttpContextServletHandler extends SolonServletHandler {
4040
public void init() throws ServletException {
4141
super.init();
4242

43-
_tempdir = (File) getServletContext().getAttribute("javax.servlet.context.tempdir");
43+
_tempdir = (File) getServletContext().getAttribute("jakarta.servlet.context.tempdir");
4444

4545
String fileOutputBuffer = getServletConfig().getInitParameter("fileOutputBuffer");
4646
if (fileOutputBuffer != null) {

solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/main/java/org/noear/solon/boot/jetty/integration/JettyPlugin.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.noear.solon.boot.jetty.integration;
1717

18+
import org.eclipse.jetty.ee11.jsp.JettyJspServlet;
1819
import org.noear.solon.Solon;
1920
import org.noear.solon.Utils;
2021
import org.noear.solon.boot.ServerConstants;
@@ -69,17 +70,10 @@ private void start0(AppContext context) throws Throwable {
6970
//初始化属性
7071
ServerProps.init();
7172

72-
Class<?> jspClz = ClassUtil.loadClass("org.eclipse.jetty.jsp.JettyJspServlet");
73-
74-
// if (ServerProps.request_maxBodySize > 0) {
75-
// System.setProperty(ContextHandler.MAX_FORM_CONTENT_SIZE_KEY,
76-
// String.valueOf(ServerProps.request_maxBodySize));
77-
// }
78-
79-
if (jspClz == null) {
80-
_server = new JettyServer();
81-
} else {
73+
if (ClassUtil.hasClass(() -> JettyJspServlet.class)) {
8274
_server = new JettyServerAddJsp();
75+
} else {
76+
_server = new JettyServer();
8377
}
8478

8579
_server.enableWebSocket(context.app().enableWebSocket());

solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/main/java/org/noear/solon/boot/jetty/http/JtJspStarter.java renamed to solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/main/java/org/noear/solon/boot/jetty/jsp/JspLifeCycle.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.noear.solon.boot.jetty.http;
16+
package org.noear.solon.boot.jetty.jsp;
1717

1818
import org.apache.tomcat.util.scan.StandardJarScanner;
1919
import org.eclipse.jetty.ee11.apache.jsp.JettyJasperInitializer;
2020
import org.eclipse.jetty.ee11.servlet.ServletContextHandler;
2121
import org.eclipse.jetty.util.component.AbstractLifeCycle;
2222

23-
public class JtJspStarter extends AbstractLifeCycle
23+
public class JspLifeCycle extends AbstractLifeCycle
2424
implements ServletContextHandler.ServletContainerInitializerCaller {
2525
JettyJasperInitializer sci;
2626
ServletContextHandler context;
2727

28-
public JtJspStarter(ServletContextHandler context) {
28+
public JspLifeCycle(ServletContextHandler context) {
2929

3030
this.sci = new JettyJasperInitializer();
3131
this.context = context;
@@ -34,7 +34,6 @@ public JtJspStarter(ServletContextHandler context) {
3434

3535
@Override
3636
protected void doStart() throws Exception {
37-
3837
ClassLoader old = Thread.currentThread().getContextClassLoader();
3938
Thread.currentThread().setContextClassLoader(context.getClassLoader());
4039
try {

solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/main/resources/META-INF/native-image/org.noear/solon.boot.jetty/resource-config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"resources": {
33
"includes": [
44
{
5-
"pattern": "javax/servlet/LocalStrings.*\\.properties"
5+
"pattern": "jakarta/servlet/LocalStrings.*\\.properties"
66
},
77
{
8-
"pattern": "javax/servlet/http/LocalStrings.*\\.properties"
8+
"pattern": "jakarta/servlet/http/LocalStrings.*\\.properties"
99
}
1010
]
1111
}

solon-jakarta-projects/solon-view/solon-view-jsp-jakarta/src/main/java/org/noear/solon/view/jsp/integration/ViewJspPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.noear.solon.view.jsp.integration;
1717

18+
import jakarta.servlet.ServletResponse; //用于检测
19+
1820
import org.noear.solon.core.AppContext;
1921
import org.noear.solon.core.Plugin;
2022
import org.noear.solon.core.util.ClassUtil;
@@ -25,7 +27,7 @@ public class ViewJspPlugin implements Plugin {
2527

2628
@Override
2729
public void start(AppContext context) {
28-
if (ClassUtil.loadClass("jakarta.servlet.ServletResponse") == null) {
30+
if (ClassUtil.hasClass(() -> ServletResponse.class) == false) {
2931
LogUtil.global().warn("View: jakarta.servlet.ServletResponse not exists! JspRender failed to load.");
3032
return;
3133
}

0 commit comments

Comments
 (0)