09 12 11 Java Web学习笔记-Jsp简单总结

来源:互联网 发布:淘宝选词工具有哪些 编辑:程序博客网 时间:2024/06/04 19:46



Jsp脚本元素的三种格式:
    表达式:
        <%=exprssion%> 将表达式的值输出到前台。
        <jsp:expression>Java Expression</jsp:expresion>

    Scriptlet:
        <%Java code%>将Java代码块插入到Servlet的service方法
          <jsp:scritplet>code</jsp:scritptlet>

    Declaration:<%!code%>声明,在任何方法之外,如果声明一个变量那么这个变量就是类的属性。

    Jsp中的隐含对象:request,response,out,session,application,config,pageContext,page
   
     跳转:
        request.sendRedirect("URL");
        request.getRequestDispacher("URL").forward(request,reponse);

    Jsp指令标签:
             <%@directive attribute="value" aattribute2="value2"..%>
             <%@page %>
             <%@include file=""%>
             <%@taglib uri="" prefix=""%>

    Jsp动作指令标签:
             <jsp:include file="url"></jsp:include>

             <jsp:forward page="url"/>

             <jsp:useBean id="" class="" scope="">   
            <jsp:setProperty name="" property="" value=""/>
            <jsp:setProperty name="" property="" value=""/>
             </jsp:userBean>

    EL 语法结构:
        1、${expression}
        2、[] . 来去对象的属性([]可以动态的取值)
        3、${varName}声明变量
        4、可访问的元素类型:MAP、LIST、Arrary、JavaBean
        5、EL常用隐含属性:
            ${param.inputName}相当于 request.getParameter ("inputName");

   ?            ${paramValues.inputName[i]}相当于request.getParamterValues("inputName")[i]

   ?             ${pageScope.userBeanId.propertyName}获得scope=“page” id=“userBeanId”的javaBean对象的属                性值.
           
            ${requestScope.attrName}相当于 request.getAttribute(“attrName”)

            ${sessionScope.attrName}相当于 session.getAttribute(“attrName”)

            ${applicationScope.attrName}相当于? application.getAttribute(“attrName”)

            访问JavaBean:${beanId.fildName} 相当于 <%=beanId.getFiledName()>

            访问Map类型:${mapName.kayName}相当于 mapName. get(“kayName”)

            访问List类型:${listName[i]}相当于 listName.get(i)
    ?
    ?            <%@ page isELIgnored="false" %>可以使用EL

    JSTL 语法结构:
        核心标签库:
            1、<c:out value="" default="" escapeXml=""></c:out>用于计算一个表达式并将结果输出

            2、<c:set var="" value="" scope="" target="" property=""></c:set>用于设置范围变量的值或者                    javabean 对象的属性
           
            3、<c:remove var="" scope=""/> 相对 <c:set> 其作用是移除范围变量.

            4、<c:catch var=”exception”>
               <%
                可能产生异常
               %>
               </c:catch>
               ${exception}<br>

            5、<c:if test="" var="" scope="" >
                This is your first visit .
               </c:if>

            6、<c:choose>     实现互斥条件执行,类似于 java 中的 if else.
               <c:when test="">
                   out1
               </c:when>
               <c:when test="">
                   out2
               </c:when>
               <c:otherwise>

               </c:otherwise>
                   </c:choose>

            7、<c:forEach items="${arry}" var="item">       
                    ${item.fileName}
                 </c:forEach>

            8、<c:forEach begin="0" end="2" var="i" step="1">
                ${array[i]}<br>
               </c:forEach>




  ?


       






原创粉丝点击