日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jsp中%! %

發布時間:2024/4/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jsp中%! % 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

jsp中<%! %>

1 <body> 2 <%! 3 4 //1、可定義方法 5 public String outMethod(){ 6 return "outMethod"; 7 } 8 //2、可定義static方法 9 public static String outStaticMethod(){ 10 return "outStaticMethod"; 11 } 12 //3、可定義static屬性 13 public static int count = 0; 14 15 //4、不可以使用out對象 16 %> 17 18 <% 19 //1、不可定義方法 20 //2、不可定義static方法 21 //3、不可定義static屬性 22 23 //可以使用out對象 24 out.print(outMethod()); 25 out.print("<br>"); 26 out.print(outStaticMethod()); 27 out.print("<br>"); 28 out.print(count); 29 %> 30 </body>

經Tomcat編譯后,生成的java文件如下:

1 package org.apache.jsp; 2 3 import javax.servlet.*; 4 import javax.servlet.http.*; 5 import javax.servlet.jsp.*; 6 7 public final class test_jsp extends org.apache.jasper.runtime.HttpJspBase 8 implements org.apache.jasper.runtime.JspSourceDependent { 9 10 11 12 //1、可定義方法 13 public String outMethod(){ 14 return "outMethod"; 15 } 16 //2、可定義static方法 17 public static String outStaticMethod(){ 18 return "outStaticMethod"; 19 } 20 //3、可定義static屬性 21 public static int count = 0; 22 23 //4、不可以使用out對象 24 25 private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory(); 26 27 private static java.util.List _jspx_dependants; 28 29 private javax.el.ExpressionFactory _el_expressionfactory; 30 private org.apache.AnnotationProcessor _jsp_annotationprocessor; 31 32 public Object getDependants() { 33 return _jspx_dependants; 34 } 35 36 public void _jspInit() { 37 _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory(); 38 _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName()); 39 } 40 41 public void _jspDestroy() { 42 } 43 44 public void _jspService(HttpServletRequest request, HttpServletResponse response) 45 throws java.io.IOException, ServletException { 46 47 PageContext pageContext = null; 48 HttpSession session = null; 49 ServletContext application = null; 50 ServletConfig config = null; 51 JspWriter out = null; 52 Object page = this; 53 JspWriter _jspx_out = null; 54 PageContext _jspx_page_context = null; 55 56 57 try { 58 response.setContentType("text/html; charset=utf-8"); 59 pageContext = _jspxFactory.getPageContext(this, request, response, 60 null, true, 8192, true); 61 _jspx_page_context = pageContext; 62 application = pageContext.getServletContext(); 63 config = pageContext.getServletConfig(); 64 session = pageContext.getSession(); 65 out = pageContext.getOut(); 66 _jspx_out = out; 67 68 out.write("\r\n"); 69 out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\r\n"); 70 out.write("<html>\r\n"); 71 out.write("<head>\r\n"); 72 out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n"); 73 out.write("<title>Insert title here</title>\r\n"); 74 out.write("</head>\r\n"); 75 out.write("<body>\r\n"); 76 out.write("\r\n"); 77 out.write("\r\n"); 78 79 //1、不可定義方法 80 //2、不可定義static方法 81 //3、不可定義static屬性 82 83 //可以使用out對象 84 out.print(outMethod()); 85 out.print("<br>"); 86 out.print(outStaticMethod()); 87 out.print("<br>"); 88 out.print(count); 89 90 out.write("\r\n"); 91 out.write("</body>\r\n"); 92 out.write("</html>"); 93 } catch (Throwable t) { 94 if (!(t instanceof SkipPageException)){ 95 out = _jspx_out; 96 if (out != null && out.getBufferSize() != 0) 97 try { out.clearBuffer(); } catch (java.io.IOException e) {} 98 if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); 99 } 100 } finally { 101 _jspxFactory.releasePageContext(_jspx_page_context); 102 } 103 } 104 }

在生成的java文件中,我們可以看到,<%! %>中的代碼對應于java類文件的成員方法、靜態方法,靜態變量,而<%? %>中的代碼對應于java類文件的_jspService方法中的代碼(_jspService對應于servlet中的service方法),這也就是為什么在<% %>中不能聲明方法、靜態變量的原因了(方法中是不可以再創建方法的)

?

轉載于:https://www.cnblogs.com/Renyi-Fan/p/8041072.html

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的jsp中%! %的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。