jspѧϰ
<c:if>ÓÃÓÚ
Á÷³Ì¿ØÖÆ
Óï·¨
1:
<c:if
test=”testCondition” var=”varName”
[scope=”page|request|session|application”]/>
Óï·¨
2:
<c:if
test=”testCondition” var=”varName”
[scope=”page|request|session|application”]>
ÊôÐÔ
Ãû³Æ
˵Ã÷
EL
ÀàÐÍ
±ØÐë
ĬÈÏÖµ
test
Èç¹û±í´ïʽµÄ½á¹ûΪtrue
£¬ÔòÖ´Ðб¾ÌåÄÚÈÝ£¬false
ÔòÏà·´
Y
boolean
ÊÇ
ÎÞ
var
ÓÃÀ´´¢´ætest
ÔËËãºóµÄ½á¹û£¬¼´true
»òfalse
N
String
·ñ
ÎÞ
scope
var
±äÁ¿µÄJSP
·¶Î§
N
String
·ñ
page
eg£º
<%@ page
language="java" import="java.util.*"
pageEncoding="UTF-8"%>
<%@ taglib
uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
</head>
<body>
<h2><c:out value="<c:if>"/></h2>
<c:if
test="${param.username=='username' }" var="name"
scope="page">
hello,admin
</c:if>
<br>
result:${condition }
</body>
</html>
<c:choose> Ñ¡Ôñ±êÇ©
<c:choose>
±¾ÉíÖ»µ±×ö
<c:when>
ºÍ
<c:otherwise>
µÄ¸¸±êÇ©
Óï·¨
:
<c:choose>
±¾ÌåÄÚÈÝÖпÉÒÔº¬ÓÐ
(<when> <otherwise>)£¬¿ÉÒÔÓÉ1
»ò¶à¸ö
<c:when>£¬0
»ò
1
¸ö
<c:otherwise>
</c:choose>
<c:when> ±êÇ©
Óï·¨
:
<c:when
test=”testCondition”>
±¾ÌåÄÚÈÝ
<c:when>
ÊôÐÔ
Ãû³Æ
˵Ã÷
EL
ÀàÐÍ
±ØÐë
ĬÈÏÖµ
test
Èç¹û±í´ïʽµÄ½á¹ûΪtrue
£¬ÔòÖ´Ðб¾ÌåÄÚÈÝ£¬false
ÔòÏà·´
Y
boolean
ÊÇ
ÎÞ
<c:when>
±ØÐëÔÚ
<c:choose>
ºÍ
</c:choose>
Ö®¼ä
ÔÚͬһ¸ö
<c:choose>
ÖÐʱ£¬
<c:when>
±ØÐëÔÚ
<c:otherwise>
Ö®¼ä
<c:otherwise> ±êÇ©
ÔÚͬһ¸ö
<c:otherwise>
Ïà¹ØÎĵµ£º
tomcat6.0 + JSP + mysqlÊý¾Ý¿âÁ¬½Ó³ØÅäÖÃ
»·¾³£ºtomcat6.0 £¬mySQL 5.021
°ÑmysqlÇý¶¯°ü·Ö±ð·Åµ½%TOMCAT_HOME%/lib ºÍÄãµÄÓ¦ÓõÄWEB-INF\libÎļþ¼ÐÏÂÃæ
1¡¢ÐÞ¸Ä%TOMCAT_HOME%/conf/server.xml,Ìí¼ÓÈçÏÂÄÚÈÝ£¨²¿·Ö²ÎÊýÇë±¾µØ»¯£©£º
<Context path="/web" docBase="web" ......
JSPºÍSERVLETµ½µ×ÔÚÓ¦ÓÃÉÏÓÐÊ²Ã´Çø±ð£¬ºÜ¶àÈ˸㲻Çå³þ¡£ÎÒÀ´ºú³¶¼¸¾ä°É¡£¼òµ¥µÄ˵£¬SUNÊ×ÏÈ·¢Õ¹³öSERVLET£¬Æä¹¦ÄܱȽÏÇ¿¾¢£¬ÌåϵÉè¼ÆÒ²ºÜÏȽø£¬Ö»ÊÇ£¬ËüÊä³öHTMLÓï¾ä»¹ÊDzÉÓÃÁËÀϵÄCGI·½Ê½£¬ÊÇÒ»¾äÒ»¾äÊä³ö£¬ËùÒÔ£¬±àдºÍÐÞ¸ÄHTML·Ç³£²»·½±ã¡£
ºóÀ´SUNÍÆ³öÁËÀàËÆÓÚASPµÄÏâǶÐ͵ÄJSP£¬°ÑJSP TAGÏâǶµ½HTMLÓï¾äÖУ¬ÕâÑù£¬¾Í ......
µÚÒ»²½£º½¨Á¢Ò»¸öcode.jspµÄÒ³Ãæ£¬²úÉúËæ»úÂë
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"
import="java.io.*,
java.util.*,
& ......
½üÆÚµÄÒ»¸öÏîÄ¿ÐèҪʵÏÖÉãÏñͷͼÏñ²É¼¯£¬¾¹ýһϵÁеÄÕÛÌÚÒÔºó£¬ÖÕÓÚʵÏÖÁËÕâ¸ö¹¦ÄÜ£¬ÏÖÕûÀíһϡ£
±¾Éí¾Íjava¼¼ÊõÀ´Ëµ£¬ÒªÊµÏÖÉãÏñÍ·¶þ´Î¿ª·¢£¬²É¼¯ÉãÏñͷͼƬ£¬ÐèҪʹÓõ½JMF£¬JMFÊʺÏʹÓÃÔÚj2se³ÌÐòµ±ÖУ¬ÎÒÐèÒªÔÚweb³ÌÐòÖе÷ÓÃÉãÏñÍ·£¬ºÜÃ÷ÏÔJMFÊǸ㲻¶¨ÁË£¬Ïë¹ýдһ¸öapplet³ÌÐò£¬Ö»ÊÇÄǶ«Î÷ÒªÇó¿Í»§¶Ë±ØÐëÒªÓÐjre»·¾ ......
1.request¶ÔÏó
¿Í»§¶ËµÄÇëÇóÐÅÏ¢±»·â×°ÔÚrequest¶ÔÏóÖУ¬Í¨¹ýËü²ÅÄÜÁ˽⵽¿Í»§µÄÐèÇó£¬È»ºó×ö³öÏìÓ¦¡£ËüÊÇHttpServletRequestÀàµÄʵÀý¡£
ÐòºÅ ·½ ·¨ ˵ Ã÷
1 object getAttribute(String name) ·µ»ØÖ¸¶¨ÊôÐÔµÄÊôÐÔÖµ
2 Enumeration getAttributeNames() ·µ»ØËùÓпÉÓÃÊôÐÔÃûµÄö¾Ù
3 String getCharacterEncoding( ......