<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # jsp腳本和注釋 servlet腳本會變翻譯到和webapps平級的work文件夾下 在webapps文件下,有個conf文件夾,這個文件下有web.xml jsp本質就是servlet jsp腳本: ~~~ 1)<%java代碼%> ----- 內部的java代碼翻譯到service方法的內部 2)<%=java變量或表達式 %> ----- 會被翻譯成service方法內部out.print(),就是頁面顯示 3)<%!java代碼%> ---- 會被翻譯成servlet的成員的內容,就是類成員變量 ~~~ jsp注釋: 不同的注釋可見范圍是不同 ~~~ 1)Html注釋:<!--注釋內容--> ---可見范圍 jsp源碼、翻譯后的servlet、頁面顯示html源碼 2)java注釋://單行注釋 /*多行注釋*/ --可見范圍 jsp源碼 翻譯后的servlet 3)jsp注釋:<%--注釋內容--%> ----- 可見范圍 jsp源碼可見 ~~~ # jsp運行原理-----jsp本質就是servlet jsp在第一次被訪問時會被Web容器翻譯成servlet,在執行 過程: 第一次訪問---->helloServlet.jsp---->helloServlet_jsp.java---->編譯運行 PS:被翻譯后的servlet在Tomcat的work目錄中可以找到 # jsp指令(3個) jsp的指令是指導jsp翻譯和運行的命令,jsp包括三大指令: 1)page指令 --- 屬性最多的指令(實際開發中page指令默認) 屬性最多的一個指令,根據不同的屬性,指導整個頁面特性 格式:<%@ page 屬性名1= "屬性值1" 屬性名2= "屬性值2" ...%> 常用屬性如下: language:jsp腳本中可以嵌入的語言種類 pageEncoding:當前jsp文件的本身編碼---內部可以包含contentType contentType:response.setContentType(text/html;charset=UTF-8) session:是否jsp在翻譯時自動創建session,默認session是true import:導入java的包 errorPage:當當前頁面出錯后跳轉到哪個頁面 isErrorPage:當前頁面是一個處理錯誤的頁面 buffer : 緩沖區out的大小,buffer="8kb" ~~~ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="true" import="java.util.*" errorPage="/error.jsp"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% int i =3; System.out.println(i); List list = new ArrayList(); //或者 java.util.List list1 = new java.util.ArrayList(); %> <%=i %> <%! String str = "你好"; %> <%=str %> </body> </html> ~~~ 錯誤全局的話要在web.xml那配置 ~~~ <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>w1</display-name> <!-- 設置web應用的全局錯誤頁面 --> <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error2.jsp</location> </error-page> </web-app> ~~~ 2)include指令 頁面包含(靜態包含)指令,可以將一個jsp頁面包含到另一個jsp頁面中 格式:<%@ include file="被包含的文件地址"%> 3)taglib指令 在jsp頁面中引入標簽庫(jstl標簽庫、struts2標簽庫) 格式:<%@ taglib uri="標簽庫地址" prefix="前綴"%> # jsp內置/隱式對象(9個) jsp被翻譯成servlet之后,service方法中有9個對象定義并初始化完畢,我們在jsp 腳本中可以直接使用這9個對象 在翻譯后的servlet頁面有這個 ![](https://box.kancloud.cn/9d656e4530e07880bf13289bbe8b8a48_1174x550.png) ![](https://box.kancloud.cn/318cc183c79177bd3df6137eafe3d757_1212x470.jpg) ![](https://box.kancloud.cn/584e139d4afe7087ad4b74dd926692d7_1358x808.jpg) exception是獲取上個頁面錯誤信息 ~~~ <% exception.getMessage(); %> ~~~ (1)out對象 out的類型:JspWriter out作用就是想客戶端輸出內容----out.write() out緩沖區默認8kb 可以設置成0 代表關閉out緩沖區 內容直接寫到response緩沖器 8k大小,是在page指令那buffer設置 tomcat默認會對response緩存區獲取內容,最終都要寫到response緩沖區 ![](https://box.kancloud.cn/3df8bcdd9715799e3eb56947dfcacb3d_1173x538.png) (2)pageContext對象 jsp頁面的上下文對象,作用如下: page對象與pageContext對象不是一回事 1)pageContext是一個域對象 ~~~ setAttribute(String name,Object obj) getAttribute(String name) removeAttrbute(String name) ~~~ pageContext可以向指定的其他域中存取數據 ~~~ setAttribute(String name,Object obj,int scope) //第三參數用 PageContext.XX 來獲取 getAttribute(String name,int scope) removeAttrbute(String name,int scope) findAttribute(String name) ~~~ ~~~ <body> 111 <!-- 然后是這個 --> <% pageContext.setAttribute("1",2); %> <% Object i = pageContext.getAttribute("1"); out.write(i.toString()); //第三是這個 response.getWriter().write("aaa");//先輸出這個 %> <%="ddddd" %><!-- 最后是這個 --> </body> ~~~ **---依次從pageContext域,request域,session域,application域中獲 取屬性,在某個域中獲取后將不在向后尋找** **四大作用域的總結: page域:當前jsp頁面范圍 request域:一次請求 session域:一次會話 application域:整個web應用** 2)**可以獲得其他8大隱式對象** ~~~ 例如: pageContext.getRequest() pageContext.getSession() ~~~ # jsp標簽(動作) 1)頁面包含(動態包含):<jsp:include page="被包含的頁面"/> 這是動態包含,靜態包含還是不同文件,編譯時運行,把他包含進去 靜態包含是一個文件 2)請求轉發:<jsp:forward page="要轉發的資源" />
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看