1.JSP入门演示:
此jsp页面会显示当前时间:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" errorPage="/errors/error.jsp"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JSP入门(输出时间)</title> </head> <body> 当前时间值是: <% Date date=new Date(); String time = date.toLocaleString(); out.write(time); %> <br/> <%= time %> </body> </html>
2.静态包含
静态包含是几个JSP页面包含在一个JSP页面中,翻译成的Servlet也是一个
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>include指令</title> </head> <body> <%@include file="/public/head.jsp" %> aaaaaaaaaaaaaaaaaaaaaaaaa<br/> <%@include file="/public/foot.jsp" %> </body> </html>
3.动态包含
动态包含是几个JSP页面包含在一个JSP页面中,翻译成的Servlet也是多个,只不过是访问时服务器把多个Servlet整合在一起
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>动态包含</title> </head> <body> <% request.getRequestDispatcher("/public/head.jsp").include(request,response); %> bbbbbbbbbbbbbbbbbbbbbb<br/> <% request.getRequestDispatcher("/public/foot.jsp").include(request,response); %> </body> </html>
转载请注明出处: http://blog.csdn.net/acmman