您的位置:首页 > Web前端 > JavaScript

jsp学习笔记

2015-12-03 19:24 766 查看

<a href="javascript:;" target="_blank">

停留在此页面,重新加载新的blank窗口

 

forEach 中的items是setAttribute的值,varStatus参数:

index:成员索引(下标从0开始)

count:成员的数目从1开始

first:是否为第一个成员

last:是否为最后一个成员

 

 

 

${requestScope}操作的是request的作用域,相当于request.getAttribute();不过EL比这个更智能些,
它不用强制类型转换就可以拿到了真实对象的值。
request.getParamter(),获取的是页面传递的值,可以是jsp传jsp,jsp传servle,
常见的就是表单传过来或者是url传过来?xx=xx形式这种形式下,${requestScope是拿不到的},
好像要用${param},要不就是${paramValues},应该是${param.xxx}吧,如果没记错的话。

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<!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>
    <%
        request.setAttribute("list", "list");
        request.setAttribute("userName", "password");
    %>
    <c:out value="helloworld">
        <br>
    hello world ${"hello world"}<br>
    </c:out>
    <c:out value="${list}"></c:out>
    <br>
    <c:out value="<h1>你好</h1>" escapeXml="false"></c:out>
    <c:out value="${userName}">文本内容</c:out>
    <c:out value="${userName}"></c:out>

    <c:set value="梅海风" var="user" scope="request"></c:set>
    ${user}
    <%
        request.setAttribute("map", "map");
    %>
    <%--<!--<c:set value="JackMei" property="username" target="${map}"></c:set>-->--%>
    <c:remove var="map" scope="request" />
    <c:out value="${map }" default="没有值"></c:out>

    <c:catch var="Exception">
        <%
            int i = 100 / 0;
        %>
    </c:catch>
    异常:
    <c:out value="${Exception }"></c:out>
    异常原因:
    <c:out value="${Exception.cause }"></c:out>
    异常消息:
    <c:out value="${Exception.message }"></c:out>
    异常轨迹:
    <c:out value="${Exception.stackTrace }"></c:out>
    <%--<c:if test="${person.username!=null}" scope="request">
    用户登录成功!
    </c:if>--%>
    <%
        request.setAttribute("age", "18");
    %>
    <c:choose>
        <c:when test="${age>70 }">老年人</c:when>
        <c:when test="${age<=18 }">未成年人</c:when>
        <c:otherwise>输入错误</c:otherwise>
    </c:choose>
</body>
</html>

 

Forward与Redirect

Forward:转发页面和转发到的页面可以共享request里面的数据。

Redirect:不能共享request里面的数据

 

rward简单来说就是在服务器端完成叶面跳转,服务端从A页forward到B页,对于客户端来说一直都在访问A页,不知道有个B页存在(所以structs几乎把所有的jsp文件藏起来,客户端地址栏看不到jsp,就是因为structs的大部分jsp页都是在Action里面通过forward跳转)。
redirect就容易理解的多了,从A页forward到B页,服务端告诉客户端,你要从A跳到B,由客户端发出指挥,所以客户端地址栏看到从A页变成B页了。

 

 

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: