The reference code is as follows:
Com.atguigu.struts2.app.converters.DateConverter.java |
Public DateFormat GetDateFormat () { if (dateformat = =null) { // Gets the current WEB Application Initialization Parameters pattern ( This parameter is in the Web . XML file under web-inf ) // get the first time you use it, and load the relevant information // This method is used /struts2-6/src/xwork-conversion.properties configuration file //xwork-conversion.properties contents of the configuration file: //java.util.date=com.atguigu.struts2.app.converters.dateconverter ServletContext ServletContext = Servletactioncontext. Getservletcontext (); System. out. println (servletcontext); String pattern = ServletContext. Getinitparameter ("pattern"); DateFormat = new SimpleDateFormat (pattern); } return DateFormat; } |
How to obtain (read) the parameters of the Web. XML configuration file