JSTL 与 EL
实践:
My JSP 'hello.jsp' starting page
------------------------
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ 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 'hello.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>
<form method="post" action="hello_result.jsp" name="INPUTFORM" ><p> <input type="text" value="我的第一个MYECLIPSE项目!" name="hello" size="50"><input type="submit" value="提交" name="button1"></p>
</form>
<%
pageContext.setAttribute("name","pagename");
session.setAttribute("name","sessionname");
application.setAttribute("name","appname");
request.setAttribute("name","rqtname");
%>
<a href="2.jsp" target="_blank">JSTL core </a><br>
<c:out value="jstl"/>
<c:set value="pageStr" var="Str" scope="page"/>
<c:set value="requestStr" var="Str" scope="request"/>
<c:set value="sessionStr" var="Str" scope="session"/>
<c:set value="appStr" var="Str" scope="application"/>
</body>
</html>
hello_result.jsp'
--------------------
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
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 'hello_result.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.setCharacterEncoding("GBK");
String temp=request.getParameter("hello");
out.println(temp);
%>
<br>${param.hello}
<br>${pageScope.name }
<br>${requestScope.name }
<br>${sessionScope.name}
<br>${applicationScope.name }
<br>${pageContext.request.remoteAddr }
</body>
</html>
2.jsp
------------------
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ 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 '2.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>
<a href="2.jsp#end">end</a><br>${param.hello}
<br>${pageScope.name }
<br>${requestScope.name }
<br>${sessionScope.name}
<br>${applicationScope.name }
<br>${pageContext.request.remoteAddr }
<%
Enumeration enm=request.getHeaderNames();
pageContext.setAttribute("header",enm);
while(enm.hasMoreElements()){
String n;
n=enm.nextElement().toString();
out.println("header-- "+n+""+" :");
request.setAttribute("enme",n);
%>
<c:out value="${header[requestScope.enme]}"/><br>
<%
}
%>
<c:out value="<b><P>字体样式 escapeXml=true</P></b>" escapeXml="true"></c:out>
<c:out value="<b><P>字体样式 escapeXml=fasle</P></b>" escapeXml="false" ></c:out>
<c:out value="${pageScope.Str}"/>
<c:out value="${requestScope.Str }"/>
<c:out value="${sessionScope.Str}"/>
<c:out value="${applicationScope.Str}"/>
<%
out.println(application.getAttribute("Str"));
%>
<br>
<c:remove var="name" scope="application" />
<c:out value="${applicationScoe.name}">no data</c:out>
<c:catch var="err_message">
<%String s="a b";
int i=Integer.parseInt(s);
out.println(i);
%>
</c:catch>
<br>${err_message }
<c:set var="u" value="2"/>
<br>${u+7 }
<br>
<c:if test="1==3">
1==3 开玩笑!
</c:if>
<br>
<c:choose>
<c:when test="1==4">1==4 呵呵!</c:when>
<c:otherwise>1!=4</c:otherwise>
</c:choose>
<br>
-------------------<br>
<c:forEach items="${header}" var="itm">${itm}<br></c:forEach>
--------------------<br>
<c:forTokens items="131001;131002;131003;131004;131005" delims=";" var="num">
${num }<br>
</c:forTokens>
<br>
<c:forEach items="1,2,3,4" var="i">
${i }<br>
</c:forEach>
<c:forEach items="1-2-3-4" var="j">
${j }<br>
</c:forEach>
<br>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<p>
hello_result.jsp:<br>
<c:import url="hello_result.jsp">
<c:param name="hello" value="kkkkkkk"></c:param>
</c:import>
<br>!!!!!!!!!!!!!!!!!!
</p>
<c:import url="http://baidu.com/index.html" charEncoding="gbk"></c:import>
<br>
<a name="end">end</a><br>
<p/>
<a href="3.jsp"><c:redirect></a><br> _fcksavedurl=""3.jsp"><c:redirect></a><br>" _fcksavedurl=""3.jsp"><c:redirect></a><br>"
<br>
</body>
</html>
3.jsp
------------
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ 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 '3.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>
This is my JSP page. <br>
<c:redirect url="http://www.google.cn"></c:redirect>
<c:out value=" no kiss you"></c:out>
</body>
</html>