1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2;
22
23 import com.opensymphony.xwork2.ActionContext;
24 import org.apache.struts2.views.util.UrlHelper;
25
26 import javax.servlet.Servlet;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import javax.servlet.jsp.HttpJspPage;
30 import java.util.Map;
31
32 /***
33 * Maintains a cache of jsp locations -> servlet instances for those jsps. When a jsp is requested
34 * from the cache, the cache will block if the jsp was not compiled already, and wait for the compilation
35 */
36 public abstract class JSPRuntime {
37
38 protected static final ServletCache servletCache = new ServletCache();
39
40 public static void clearCache() {
41 servletCache.clear();
42 }
43
44 public static void handle(String location) throws Exception {
45 handle(location, false);
46 }
47
48 public static void handle(String location, boolean flush) throws Exception {
49 final HttpServletResponse response = ServletActionContext.getResponse();
50 final HttpServletRequest request = ServletActionContext.getRequest();
51
52 int i = location.indexOf("?");
53 if (i > 0) {
54
55 Map parameters = ActionContext.getContext().getParameters();
56 String query = location.substring(i + 1);
57 Map queryParams = UrlHelper.parseQueryString(query, true);
58 if (queryParams != null && !queryParams.isEmpty())
59 parameters.putAll(queryParams);
60 location = location.substring(0, i);
61 }
62
63 Servlet servlet = servletCache.get(location);
64 HttpJspPage page = (HttpJspPage) servlet;
65
66 page._jspService(request, response);
67 if (flush)
68 response.flushBuffer();
69 }
70 }