jsp 基础3

来源:互联网 发布:滚齿机挂轮计算软件 编辑:程序博客网 时间:2024/05/17 23:19
 

指令
  page
    <%@ page import=""%>
    <%@ page contentType=""%>
    <%@ page pageEncoding=""%>
 
  taglib  导入标签库
    <%@ taglib uri="" prefix=""%>

动作
  request.getRequestDispatcher().forward()
  <jsp:forward page="" />
  request.getRequestDispatcher().include();
  <jsp:include page="" />
 
 
----------------------------------------------
内置
  request
  response
  session
 ServletContext application
  pageContext

--------------------------------------------
MVC 
    Servlet (控制) --- Biz(DAO)(模型) --- JSP 显示


JSP   把jsp中java代码替换  


    1  EL表达式
       1 必须书写在jsp中
       2 作用
            用于替换原有 输出脚本
            <%= "xxx" %>
           
            辅助作用:
            0  可以进行运算
                1 算术运算
                   + - * / %
                2 比较运算
                   >     gt
                   <     lt
                   >=    ge
                   <=    le
                   ==    eq
                   !=    ne
                3 逻辑运算
                   &&
                   ||
                   !
           
            1  可以方便访问在 request,session,application中存储的数据
                request.setAttribute("name",object);
                ${requestScope.name}
                session.setAttribute("name",object);
                ${sessionScope.name}
                application.setAttribute("name",object);
                ${applicationScope.name}
                pageContext.setAttribute("name",object);
                ${pageScope.name}
               
               
               
            2  可以方便的访问 java类中属性存储的数据
                ${user.id}
                ${user.password}
           
            
      
       3 怎么用
           ${}
   
   
   ------------------------------------------------------
   MVC 
     
   2 JSTL 标签库 
     作用:替换jsp中的java代码
     Java Stander Tag Lib 
     JSP  显示数据
          ${"suns"}
          ${1}
          ${user.name}
          ${user.password}
         
         *
          有条件的显示数据
          显示集合数据
         
       1 引入jstl标签库 
         jstl.jar
         stander.jar
        
       2 jsp使用 引入标签库      
         <c:set var="name" value="suns" scope="reques|session|application"/>
        
        
         在jsp中定义一个 字符串 保存在
         request session application中
        
         <c:out />
         在jsp中输出 显示结果
        
         <jsp:forward page=""/>
         <c:redirect url="/xx.jsp"/>  A.jsp ---redirect----- B.jsp
        
         
         <c:if test="${}">
           xxxx
         </c:if>
 <c:if test="${1>2}">
      <h1> 1 greater than 2 </h1>
   </c:if>
        
         页面进行判断
        
         List<User> users ;
        
         for(User u:users){
           xxxx
         }
        
         <c:forEach var="u" items="${}">
           xxxx
         </c:forEach>
         
MyEclipse JavaWeb