JSP 中设置公共模块的方法
来源:互联网 发布:淘宝客服的奖金制度 编辑:程序博客网 时间:2024/06/05 02:26
在多个JSP页面中,经常要使用相同的代码(比如:jquery插件、公共的css等),因此,我们可以把这些共有的代码放在一个指定的JSP文件中:
比如:我把这些代码都放在head.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path; request.setAttribute("ctx", basePath);%><link rel="stylesheet" type="text/css" href="${ctx }/resource/jquery-easyui-1.4.4/themes/default/easyui.css" /><link rel="stylesheet" type="text/css" href="${ctx }/resource/jquery-easyui-1.4.4/themes/icon.css" /><script type="text/javascript" src="${ctx }/resource/jquery-easyui-1.4.4/jquery.min.js"></script><script type="text/javascript" src="${ctx }/resource/jquery-easyui-1.4.4/jquery.easyui.min.js"></script><script type="text/javascript" src="${ctx }/resource/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script><script type="text/javascript" src="${ctx }/resource/DateUtil.js"></script>
因此,下次使用的时候,只要在相应的JSP页面中插入如下代码即可:
<%@ include file="/public/head.jsp"%>
比如:我的index.jsp中的代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><html><head><%@ include file="/public/head.jsp"%><base href="<%=basePath %>"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body> <div>当前的时间:<label id="time"></label></div> <a href="${ctx }/category/account_aindex.do">直接到后台</a> <a href="${ctx }/module/slide-door/slideDoor.html">一个DOM滑动门案例学习</a></body><script type="text/javascript">$(function(){ var timeStamp = Date.parse(new Date()); var date = new Date(timeStamp); var result = date.format("yyyy-MM-dd hh:mm:ss"); $("#time").text(result);})</script></html>
0 0
- JSP 中设置公共模块的方法
- JSP中errorPage设置方法
- JSP中初始化参数的设置和获取方法
- JSP中初始化参数的设置和获取方法
- idea中JSP模板{头信息}的设置方法
- VC++公共模块被调用的实现方法
- 在jsp页面 设置当前jsp页面不存储缓存的2中方法
- JSP中图片的设置
- jsp中编码的设置
- 复选框的设置和绑定公共方法
- C# winform: ComboBox 设置下拉框数据源的公共方法
- JSP默认打开方式的设置方法
- jsp设置地址栏小logo的方法
- 设置Jsp页面编码的方法
- JSP中设置session失效时间的几种方式(tomcat服务器条件下的session失 效设置方法)
- MyEclipse中调试JSP的设置
- JSP中Cookie的设置和删除
- MyEclipse - Jsp中Javascript的提示设置
- 嵌入式学习笔记(一)
- 安装genymotion时遇到的问题
- JavaEE编程技术(JSP/Servlet)
- 关于异常“The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine”的处理
- 获取手机是否开启GPS
- JSP 中设置公共模块的方法
- 树的子结构
- 信息系统项目管理师
- HDU2602_01背包问题
- 1042. Shuffling Machine (20)
- 错误:the public type XXX must be defined in its own file.
- IOS图片转base64字符串和字符串转回图片
- Java之单例模式(饿汉式、懒汉式)
- Java面向对象之八-多态