標籤:https imp oid ase load hash ring eem obj
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" />
筆記之_Java的jsp頁面全域變數