开发者

How to import my imports in JSP?

All of my JSPs have this at the top:

<%@ page language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/j开发者_如何学编程stl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tag" %>

Besides being repetitive, I have had a few hard-to-find bugs because of occasional inconsistencies. For example, a few of my JSP files were missing, isELIgnored="false", causing untold havoc.

Is there any way to put these imports into a file and then import that file in each JSP, rather than listing all of these imports in each file?


Yes, I always use an include.jsp such as:

<%@ page session="false"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="/spring-form" %>
<%@ taglib prefix="spring" uri="/spring" %>   
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>

and then reference that in the page using the import statement:

<%@ include file="/WEB-INF/jsp/include.jsp" %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜