servlet写法: import java.util.HashMap; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; public class InitSystemVariableServlet extends HttpServlet { private ServletContext servletContext; private Map<String, Object> allMap=new HashMap<String, Object>(); @Override public void init() throws ServletException { servletContext= super.getServletContext(); //全局的application allMap.put("systemTitle", "后台管理系统"); allMap.put("systemName", "教务管理系统"); //只要是页面用的往里面加 servletContext.setAttribute("baseMap", allMap); } } web.xml配置: <servlet> <servlet-name>BaseApplication</servlet-name> <servlet-class>com.wisezone.controller.InitSystemVariableServlet</servlet-class> <load-on-startup>3</load-on-startup> </servlet> 取值直接用el表达式: <title>${baseMap["systemTitle"] }</title> Freemarker数字超过3位会格式化,取消格式化用: <input type="text" value="${salary?string(‘#.00‘)}" name="salary" />
时间: 2024-10-19 19:28:30