精講jsp基礎(chǔ)教程_JSP教程
推薦:解析如何在JSP中使用Spring在JSP中使用Spring其實很容易,主要用到Spring的WebApplicationContextUtils.getWebApplicationContext函數(shù)。 要再JSP里面得到ApplicationContext需要這么做. 首先 import=org.springframework.web.context.support.*,org.springframework.context.* 然后可
jsp中Servlet的三個要素:
1.必須繼承自HttpServlet
2.必須實現(xiàn)doGet()或者doPost()
3.必須在web.xml中配置Servlet
<servlet>
<servlet-name> </servlet-name>
<servlet-class> </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> </servlet-name>
<url-pattern> </url-pattern>
</servelt-mapping>
HttpServeltRrequest:請求對象
getParameter():獲得表單元素的值
getAttribute():獲得request范圍中的屬性值
setAttribute():設(shè)置reqeust范圍中的屬性值
setCharacterEncoding():設(shè)置字符編碼
HttpSerletResponse:相應(yīng)對象
sendRedirect():外部跳轉(zhuǎn)
getWriter():獲得輸出流對象
setContentType("text/html; charset=utf-8"):設(shè)置相應(yīng)內(nèi)容格式和編碼
四種會話跟蹤方式:
1.Session
HttpSession session = request.getSession();
session.setAttribute("name", "zhangsan");
session.setAttribute("pwd", "aaa");
String name = (String) session.getAttribute("name");
2.cookie:
//創(chuàng)建Cookie
Cookie cookie = new Cookie("name", "zhangsan");
//設(shè)置Cookie的超時時間
cookie.setMaxAge(24 * 60 * 60 *60);
//把Cookie發(fā)送到客戶端
response.addCookie(cookie);
//得到客戶端發(fā)送的Cookie
Cookie [] cookies = request.getCookies();
for(int i=0; i <cookies.length; i++) {
Cookie temp = cookies[i];
String key = temp.getName();
String value = temp.getValue();
}
3.隱藏表單域
<input type="hidden" name="name" value="zhangsan" />
request.getParameter("name");
4.Url重寫
問號傳參
LoginServlet?username=zhangsan&pwd=123
String name = request.getParameter("username");
String pwd =request.getPareameter("pwd");
內(nèi)部跳轉(zhuǎn):
LoginServlet
request.getRequestDispatcher("index.jsp").forward(request, resposne);
外部跳轉(zhuǎn):
response.sendRedirect("index.jsp");
內(nèi)部跳轉(zhuǎn)是一次請求和一次響應(yīng)
外部跳轉(zhuǎn)是兩次請求和兩次響應(yīng)
ServletContext:Servlet上下文對象
它是一個公共區(qū)域,可以被所有的客戶端共享
setAttribute():向公共區(qū)域里放入數(shù)據(jù)
getAttribute():從公共區(qū)域里取數(shù)據(jù)
二:
三:三個標(biāo)準(zhǔn)范圍:request, session, ServletContext
共同點:都有setAttribute(), getAttribute()
區(qū)別:范圍不同,request < session < servletContext
四:四種會話跟蹤方式
五:服務(wù)器上的五大對象
request, response, servlet, session, servletContext
Jsp:Java Server Page
頁面構(gòu)成:7種元素
1.靜態(tài)內(nèi)容:html
2.指令:page, include, taglib:
<%@ 指令名 屬性1="屬性值1" 屬性2="屬性值2" %>
3.表達(dá)式: <%=表達(dá)式 %>
4.Scriptlet <% Java代碼 %>
5.聲明: <%! %>:變量和方法
6.動作: <jsp:動作名 屬性="屬性值"> </jsp:動作名>
7.注釋:
客戶端看不到的: <%-- --%>
客戶端可以看到的: <!-- -->
Jsp的執(zhí)行過程:
1.轉(zhuǎn)譯:Jsp--->Servlet
2.編譯:Servlet---->.class
3.執(zhí)行:.class
第一次訪問jsp的時候響應(yīng)速度較慢,后面請求時響應(yīng)速度快
腳本:
表達(dá)式: <%= %>
Scriptlet: <% %>
聲明: <%! %>
指令:
page:language, import, errorPage, isErrorpage
include:file
taglib:uri:指定標(biāo)簽庫描述符的路徑 prefix:指定標(biāo)簽的前綴
分享:詳解Java編程--基礎(chǔ)代碼的規(guī)范化命名規(guī)范 定義這個規(guī)范的目的是讓項目中所有的文檔都看起來像一個人寫的,增加可讀性,減少項目組中因為換人而帶來的損失。(這些規(guī)范并不是一定要絕對遵守,但是一定要讓程序有良好的可讀性) Package的命名 Package的名字應(yīng)該都是由一個小寫單詞組成。 Cla
- jsp response.sendRedirect不跳轉(zhuǎn)的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復(fù)習(xí)整理
- JSP腳本元素和注釋復(fù)習(xí)總結(jié)示例
- JSP FusionCharts Free顯示圖表 具體實現(xiàn)
- 網(wǎng)頁模板:關(guān)于jsp頁面使用jstl的異常分析
- JSP頁面中文傳遞參數(shù)使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項目中連接Access數(shù)據(jù)庫的配置方法
- JDBC連接Access數(shù)據(jù)庫的幾種方式介紹
- 網(wǎng)站圖片路徑的問題:絕對路徑/虛擬路徑
- (jsp/html)網(wǎng)頁上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對路徑下的圖片解決方法
- 相關(guān)鏈接:
- 教程說明:
JSP教程-精講jsp基礎(chǔ)教程
。