jsp 指令 标准标签库 动作 的使用
2012-03-03 12:40
204 查看
/********************************************************************************/ >jsp指令和动作以及标准标签库的使用 /********************************************************************************/ 0.<%@include file="ok.jsp" %> >ok.jsp中定义的成员变量和成员方法 ///////////////////////////////////////////////// // <%!public PageContext pgct=null; %> // // <%pgct=pageContext; %> // <%! // public void demonstrate_include_directive(){ // try{ // pgct.getOut().print("只有一个java文件吗?"); // }catch(Exception e){ // e.printStackTrace(); // } // } // %> // <% // demonstrate_include_directive(); // %> ////////////////////////////////////////////////// ////////////////////////////////////////////////// //>jsp_action.jsp中的代码 //<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> //<%@include file="ok.jsp" %> -->只使用了include指令 ////////////////////////////////////////////////// ////////////////////////////////////////////////// //>经过编译后 // root:\apache-tomcat-6.0.30\apache-tomcat-6.0.30\apache-tomcat-6.0.30 // \work\Catalina\localhost\jsp // \org\apache\jsp // \jsp_005faction // jsp_005faction_jsp.java-->只有一个类文件和一个java文件 // 这说明是动态包含include指令将会把自己和另外一个jsp // 进行一个合并然后再翻译成一个类来使用 ////////////////////////////////////////////////// >两个jsp合并后的代码 /***********************************************************************************/ public final class jsp_005faction_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent { public PageContext pgct=null; //在ok.jsp中定义的成员变量 public void demonstrate_include_directive(){//在ok.jsp中定义的成员方法 try{ pgct.getOut().print("只有一个java文件吗?"); }catch(Exception e){ e.printStackTrace(); } } private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory(); private static java.util.List _jspx_dependants; static { _jspx_dependants = new java.util.ArrayList(1); _jspx_dependants.add("/jsp_action/ok.jsp"); } private javax.el.ExpressionFactory _el_expressionfactory; private org.apache.AnnotationProcessor _jsp_annotationprocessor; public Object getDependants() { return _jspx_dependants; } public void _jspInit() { _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig(). getServletContext()).getExpressionFactory(); _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig(). getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName()); } public void _jspDestroy() { } public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write('\r'); out.write('\n'); out.write('\r'); out.write('\n'); String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; out.write("\r\n"); out.write("\r\n"); out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n"); out.write("<html>\r\n"); out.write(" <head>\r\n"); out.write(" <base href=\""); out.print(basePath); out.write("\">\r\n"); out.write(" \r\n"); out.write(" <title>ok.jsp</title>\r\n"); out.write(" \r\n"); out.write("\t<meta http-equiv=\"pragma\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"cache-control\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"expires\" content=\"0\"> \r\n"); out.write("\t<meta http-equiv=\"keywords\" content=\"keyword1,keyword2,keyword3\">\r\n"); out.write("\t<meta http-equiv=\"description\" content=\"This is my page\">\r\n"); out.write("\r\n"); out.write(" </head>\r\n"); out.write(" \r\n"); out.write(" <body>\r\n"); out.write(" \r\n"); out.write(" /////////////////////////////////////////////////\r\n"); out.write(" "); out.write("\r\n"); out.write(" \r\n"); out.write(" "); /****************************************/ //动态追加的代码 //pgct=pageContext; //out.write("\r\n"); //out.write(" \t"); //out.write("\r\n"); //out.write(" \t"); //demonstrate_include_directive(); /****************************************/ out.write("\r\n"); out.write(" /////////////////////////////////////////////////\r\n"); out.write(" \t</body>\r\n"); out.write("</html>\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n"); out.write("<html>\r\n"); out.write(" <head>\r\n"); out.write(" <base href=\"\">\r\n"); out.write(" \r\n"); out.write(" <title>jsp_action.jsp</title>\r\n"); out.write(" \r\n"); out.write("\t<meta http-equiv=\"pragma\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"cache-control\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"expires\" content=\"0\"> \r\n"); out.write("\t<meta http-equiv=\"keywords\" content=\"keyword1,keyword2,keyword3\">\r\n"); out.write("\t<meta http-equiv=\"description\" content=\"This is my page\">\r\n"); out.write("\r\n"); out.write(" </head>\r\n"); out.write(" \r\n"); out.write(" <body>\r\n"); out.write(" </body>\r\n"); out.write(" \r\n"); out.write(" "); out.write("</html>\r\n"); } catch (Throwable t) { if (!(t instanceof SkipPageException)){ out = _jspx_out; if (out != null && out.getBufferSize() != 0) try { out.clearBuffer(); } catch (java.io.IOException e) {} if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } } } /***********************************************************************************/ } /***********************************************************************************/ 1.<%page >指令 // <%@ page language="java" contentType="text/html;charset=Shift_JIS"%> // <%@ page import="java.util.*, java.text.*" %> // <%@ page import="java.sql.Date" %> // contentType="text/html;charset=Shift_JIS"里面可以设置字符编码但是如果 // 在pageEncoding中制定了那么在进行指定是无效的 // 如何统一制定error页面 // 当我在jsp_action.jsp使用int a=2/0;的时候就会跳转到ok.jsp不知道怎么的我自己抛出个异常他就不跳转了 // 还有那个错误页面要指定为isErrorPage="true"没指定也是可以的 // <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" errorPage="ok.jsp"%> //isELIgnored这个属性用于页面是否忽略el表达式语言的使用 2.taglib就是用于导入jsp标签的指令 /***********************************************************************************/ 3.jsp标准标签库 /***********************************************************************************/ //<s:catch var="ArithmeticException"> //<%int a =2/0;%> //</s:catch> 相当于在try{}catch(){}块中执行 >jsp标准标签有几个类别 core-->一些比较常用的标签 fmt-->用于格式字符窜如日期和数字等的标签 functions-->用于调用字符窜操作如截取字符窜,数组长短等的标签 sql-->用于数据库操作方面的标签 xml-->用于xml操作方面的标签 /***********************************************************************************/ 4.jsp标准动作 /***********************************************************************************/ >概要 JSP一共有8个标准动作(element、forward、getProperty、include、plugin、setProperty、text和useBean) 和5个只能出现在别的动作元素体内的子动作(attribute、body、fallback、param和params)。 //静态包含就是讲另外一个jsp页面执行后将这个jsp执行后的结果的html代码复制到本jsp中 //><jsp:include page="a.jsp"> ///////////////////////////////////////////////////////////// //这几个元素用于构造xml //<jsp:element name="employee"> // <jsp:attribute name="name">张三</jsp:attribute> // <jsp:body>张三是销售部经理</jsp:body> //</jsp:element> //>>生成的xml //<employee name="张三">张三是销售部经理</employee> ///////////////////////////////////////////////////////////// /***********************************************************************************/
相关文章推荐
- include指令和<jsp:include>标准动作
- JAVAWEB开发之Session的追踪创建和销毁、JSP详解(指令,标签,内置对象,动作即转发和包含)、JavaBean及内省技术以及EL表达式获取内容的使用
- JSP:使用useBean标准动作
- 关于jsp编译指令include和动作指令include的区别
- JSP的3个编译指令,7个动作指令,9个内置对象
- JSP中include指令与inlcude动作的区别
- JSP学习笔记(四)-----JSP动作的使用
- jsp第一天-jsp指令,jsp动作标签
- 4000 JSP的7个动作指令
- JSP标准动作
- JSP学习记--02(jsp基本结构、变量、注释、指令标签、动作标签)
- 通过HTTP协议标准动作使用REST WCF 服务zz
- Jsp语法、指令及动作元素
- JSP的7个动作指令之plugin指令
- JSP指令与动作
- JSP(2)jsp语法之指令元素、脚本元素、动作元素forward、注释方法
- JSP脚本和指令的使用
- Jsp的7个动作指令
- JSP动作指令
- jsp语法,指令,动作元素,内置对象