理论如下:
二.代码示例如下:
-
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
-
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
<%
-
String path = request.getContextPath();
-
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
-
%>
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
<html>
-
<head>
-
<base href="<%=basePath%>">
-
<title>My JSP 'index.jsp' starting page</title>
-
<meta http-equiv="pragma" content="no-cache">
-
<meta http-equiv="cache-control" content="no-cache">
-
<meta http-equiv="expires" content="0">
-
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
-
<meta http-equiv="description" content="This is my page">
-
<!--
-
<link rel="stylesheet" type="text/css" href="styles.css">
-
-->
-
</head>
-
<body>
-
<!-- 等同于request.setAttribute(“username”,“holly”) -->
-
在request作用域对象设值: <c:set var="username" value="holly" scope="request"/>
-
<br/>
-
<!-- 输出:out.print(request.getAttribute(“username”)) -->
-
输出request作用域对象值:<c:out value="${requestScope.username}"/>
-
<br/>
-
<%--
-
<!-- 删除作用域对象:request.removeAttribute("username") -->
-
删除作用域对象:<c:remove var="username" scope="request"/>
-
<br/>
-
<!-- 输出:out.print(request.getAttribute(“username”)) -->
-
输出request作用域对象值:<c:out value="${requestScope.username}"/>
-
<br/>
-
<!-- page,request,session,application -->
-
--%>
-
-
<c:if test="${not empty requestScope.username}">
-
<c:choose>
-
<c:when test="${requestScope.username eq 'holly'}">
-
用户名为:<c:out value="${requestScope.username}"/>
-
</c:when>
-
<c:otherwise>
-
<c:out value="登录错误!"/>
-
</c:otherwise>
-
</c:choose>
-
</c:if>
-
-
</body>
-
</html>
效果如如下:
开发人员转岗好消息!!
以上代码纯属原创 ,为了能够共同进步互相学习,如有问题或更好建议可以联系holly老师:
每周五晚8点: 斗鱼直播讲堂(房间号672217)(4月7日主题:通过生活聊java)
博客园: 红酒人生(有大量技术帖子)
想学习java,安卓,大数据,数据库,web开发,前端开发 可以来“北大青鸟南京中博软件学院”找 Holly老师 ,欢迎来咨询!
长按下方二维码关注Holly老师公众号,一起学java吧!