Java: supporting jsp-file attribute for servlet.

This closes #487 issue on GitHub.
This commit is contained in:
Max Romanov
2020-10-30 17:33:36 +03:00
parent 50af47fd7c
commit bbe4b97ca1

View File

@@ -1214,6 +1214,16 @@ public class Context implements ServletContext, InitParams
processXmlInitParam(reg, (Element) child_node); processXmlInitParam(reg, (Element) child_node);
continue; continue;
} }
if (tag_name.equals("filter-name")
|| tag_name.equals("#text")
|| tag_name.equals("#comment"))
{
continue;
}
log("processWebXml: tag '" + tag_name + "' for filter '"
+ filter_name + "' is ignored");
} }
filters_.add(reg); filters_.add(reg);
@@ -1306,6 +1316,22 @@ public class Context implements ServletContext, InitParams
reg.setLoadOnStartup(Integer.parseInt(child_node.getTextContent().trim())); reg.setLoadOnStartup(Integer.parseInt(child_node.getTextContent().trim()));
continue; continue;
} }
if (tag_name.equals("jsp-file")) {
reg.setJspFile(child_node.getTextContent().trim());
continue;
}
if (tag_name.equals("servlet-name")
|| tag_name.equals("display-name")
|| tag_name.equals("#text")
|| tag_name.equals("#comment"))
{
continue;
}
log("processWebXml: tag '" + tag_name + "' for servlet '"
+ servlet_name + "' is ignored");
} }
servlets_.add(reg); servlets_.add(reg);
@@ -1888,6 +1914,7 @@ public class Context implements ServletContext, InitParams
private boolean initialized_ = false; private boolean initialized_ = false;
private final List<FilterMap> filters_ = new ArrayList<>(); private final List<FilterMap> filters_ = new ArrayList<>();
private boolean system_jsp_servlet_ = false; private boolean system_jsp_servlet_ = false;
private String jsp_file_;
private MultipartConfigElement multipart_config_; private MultipartConfigElement multipart_config_;
public ServletReg(String name, Class<?> servlet_class) public ServletReg(String name, Class<?> servlet_class)
@@ -1921,6 +1948,21 @@ public class Context implements ServletContext, InitParams
trace("ServletReg.init(): " + getName()); trace("ServletReg.init(): " + getName());
if (jsp_file_ != null) {
setInitParameter("jspFile", jsp_file_);
jsp_file_ = null;
ServletReg jsp_servlet = name2servlet_.get("jsp");
if (jsp_servlet.servlet_class_ != null) {
servlet_class_ = jsp_servlet.servlet_class_;
} else {
setClassName(jsp_servlet.getClassName());
}
system_jsp_servlet_ = jsp_servlet.system_jsp_servlet_;
}
if (system_jsp_servlet_) { if (system_jsp_servlet_) {
JasperInitializer ji = new JasperInitializer(); JasperInitializer ji = new JasperInitializer();
@@ -1972,6 +2014,10 @@ public class Context implements ServletContext, InitParams
throw new IllegalStateException("Class already initialized"); throw new IllegalStateException("Class already initialized");
} }
if (jsp_file_ != null) {
throw new IllegalStateException("jsp-file already initialized");
}
super.setClassName(class_name); super.setClassName(class_name);
} }
@@ -1985,11 +2031,31 @@ public class Context implements ServletContext, InitParams
throw new IllegalStateException("Class already initialized"); throw new IllegalStateException("Class already initialized");
} }
if (jsp_file_ != null) {
throw new IllegalStateException("jsp-file already initialized");
}
super.setClassName(servlet_class.getName()); super.setClassName(servlet_class.getName());
servlet_class_ = servlet_class; servlet_class_ = servlet_class;
getAnnotationMultipartConfig(); getAnnotationMultipartConfig();
} }
public void setJspFile(String jsp_file) throws IllegalStateException
{
if (servlet_ != null
|| servlet_class_ != null
|| getClassName() != null)
{
throw new IllegalStateException("Class already initialized");
}
if (jsp_file_ != null) {
throw new IllegalStateException("jsp-file already initialized");
}
jsp_file_ = jsp_file;
}
private void getAnnotationMultipartConfig() { private void getAnnotationMultipartConfig() {
if (servlet_class_ == null) { if (servlet_class_ == null) {
return; return;