JSP
1,标签:
http://www.runoob.com/jsp/jsp-jstl.html
2.基本知识:
(1)Java Service Pages :支持动态内容。
(2)处理步骤:
接受web的服务请求http--->web服务器(Apache:内置了jsp的引擎)将jsp页面转发给jsp引擎--->jsp引擎将其编译为servlet类--->将servlet类转发给servlet引擎--->执行servlet,生成动态html--->浏览器显示生成的html,就好像他是一个静态页面
(3)生命周期:编译--->初始化--->执行--->销毁
编译:解析jsp--->jsp转换为servlet--->编译servlet
初始化:只执行一次,调用init方法
执行:调用service(),只接受HttpServletRequest,HttpServiceResponse
销毁:从jsp容器中删除,调用destroy方法
(4)用法:
声明:<%! **** %>
表达式:<%= ** %>
注释:<%-- *** --%>jsp引擎会忽略;<!-- ** -->html注释,浏览器会忽略;
指令:<%@ page %>(页面属性),<%@ include %>(引入某个页面),<%@ taglib %>(引入标签库)
操作:共同:id属性,scope属性
jsp:include(当请求页面时,包含一个文件);jsp:useBean(JavaBean属性值);jsp:setProperty;jsp:getProperty;jsp:plugin(生成特定代码);jsp:element(动态定义xml元素);jsp:attribute(动态定义xml元素属性);jsp:body(动态定义xml的body元素);jsp:text(用于在jsp页面和文档中编写模板);jsp:forward(转发)
九大隐含对象:request,response,out,session,application,config,pageContext,page,Exception
决策语句:两者语法有点不一样
A :if else
<%! int day = 3; %> <html> <head><title>IF...ELSE Example</title></head> <body> <% if (day == 1 | day == 7) { %> <p> Today is weekend</p> <% } else { %> <p> Today is not weekend</p> <% } %> </body> </html>
A :case when
<%! int day = 3; %> <html> <head><title>SWITCH...CASE Example</title></head> <body> <% switch(day) { case 0: out.println("It\'s Sunday."); break; case 1: out.println("It\'s Monday."); break; case 2: out.println("It\'s Tuesday."); break; case 3: out.println("It\'s Wednesday."); break; case 4: out.println("It\'s Thursday."); break; case 5: out.println("It\'s Friday."); break; default: out.println("It's Saturday."); } %> </body> </html>
循环语句:
A :for
<%! int fontSize; %> <html> <head><title>FOR LOOP Example</title></head> <body> <%for ( fontSize = 1; fontSize <= 3; fontSize++){ %> <font color="green" size="<%= fontSize %>"> JSP Tutorial </font><br /> <%}%> </body> </html>
B :while
<%! int fontSize; %> <html> <head><title>WHILE LOOP Example</title></head> <body> <%while ( fontSize <= 3){ %> <font color="green" size="<%= fontSize %>"> JSP Tutorial </font><br /> <%fontSize++;%> <%}%> </body> </html>
3.过滤器:
public class LogFilter implements Filter { 、、、、 ----->在Web.xml中
<filter> <filter-name>LogFilter</filter-name> <filter-class>LogFilter</filter-class> <init-param> <param-name>test-param</param-name> <param-value>Initialization Paramter</param-value> </init-param> </filter> <filter> <filter-name>AuthenFilter</filter-name> <filter-class>AuthenFilter</filter-class> <init-param> <param-name>test-param</param-name> <param-value>Initialization Paramter</param-value> </init-param> </filter> <filter-mapping> <filter-name>LogFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>AuthenFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
4.会话跟踪:
(1)cookie,浏览器可以禁止;(2)隐藏的表单字段,常规<a herf···>不会提交;(3)url重写,http://tutorialspoint.com/file.htm;sessionid = 12345
。每次都需要动态生成每个Url;(4)session。禁用会话跟踪:<%@ page session="false" %>
5.文件上传:
(1)表单提交方式:post。(2)enctype属性值为:multipart/formdata。(3)commons-fileupload.x.x.jar;commons-io-x.x.jar
6.页面的自动刷新:request.setIntHeader("Refresh", 5)
7.标签库:
标准标签库:<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
格式化标签库:<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
SQL标签库:<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
xml标签库:<%@ taglib prefix="xml" uri="http://java.sun.com/jsp/jstl/xml" %>
JSTL函数标签库:<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>