jsp标签库的使用
JSP动作标签:
包含标签
<jsp:include page=""/>----
JSP指令标签:<%@ include file=""%>
<%
request.getParameter
//jdbc......
//request.getRequestDispatcher("ok.jsp").forward(req,re...);
//pageContext.forward("ok.jsp");
try
{
}
catch(SQLException e)
{
<jsp:param name="msg" value="DB error...."/> //此处还可以设置参数,(是可选项)
</jsp:forward>
<%
}
%>
<jsp:forward page="ok.jsp"/>
<%
String msg = request.getParameter("msg");
if(msg!=null && msg.length()>0)
{
%>
<%=msg%>
<%
}
%>
<form ..
<%
List list = request.getAttribute("list");
<%
User user = session.getAttribute("user");
%>
<td><%=user.getUserName() %></td>
<jsp:useBean id="user" class="com.bluedot.domain.User" scope="request"/>
String userName = request.getParameter();
String age = request.getParameter();
User user = new User();
%>
<jsp:setProperty name="user" property="userName" value="<%=userName%>"/>
<%
UserManager m = new UserManagerImpl();
m.addUserInfo(user);
%>
<%
User user = request.getAttribute("user");
%>
<%=user.getUserName() %>
${user.userName}
${user["userName"]}
${requestScope.user["userName"]}
${sessionScope|applicationScope|pageScope}
head.jsp
${sessionScope.}
<%
Cookie[] cs = request.getCookies();
for(Cookie c:cs)
{
if("colorName".equals(c.getName()))
{
%>
<%=c.getValue() %>
<%
break;
}
}
%>
<%
String str = request.getHeader("User-Agent");
%>
<%%>
${header["User-Agent"]}
2.jsp
<%
String str = request.getMethod();
String str2 = request.getQueryString();
%>
<%
int i=10;
User user = new User();
user.setName("zhangsan");
user.setAge(20);
//session.setAttribute("user",user);
%>
<c:set var="i" value="10"/>
<c:set var="user" value="${pageScope.user}" scope="session"/>
User request.setAttribute("user",user);
<td>${requestScope.user.userName}</td>
<td>
Female
</c:if>
<c:choose>
<c:when test="${requestScope.user.sex eq 1}">
Male
</c:when>
<c:otherwise>
Female
</c:otherwise>
</c:choolse>
标签: 可以理解成标记,或是变量,小学数学里的X
JSP基本标签:<%!%>.......
JSP指令标签:<%@ page import........%>、<%@ include file=""%>JSP动作标签:
包含标签
<jsp:include page=""/>----
JSP指令标签:<%@ include file=""%>
.简单的使用范例
JSP----2.jsp<%
request.getParameter
//jdbc......
//request.getRequestDispatcher("ok.jsp").forward(req,re...);
//pageContext.forward("ok.jsp");
try
{
}
catch(SQLException e)
{
%>
// 动作标签 之 跳转标签
<jsp:param name="msg" value="DB error...."/> //此处还可以设置参数,(是可选项)
</jsp:forward>
<%
}
%>
<jsp:forward page="ok.jsp"/>
<%
String msg = request.getParameter("msg");
if(msg!=null && msg.length()>0)
{
%>
<%=msg%>
<%
}
%>
<form ..
<%
List list = request.getAttribute("list");
%>
// 动作标签 之 配置userBean标签
<%
User user = session.getAttribute("user");
%>
<td><%=user.getUserName() %></td>
<jsp:useBean id="user" class="com.bluedot.domain.User" scope="request"/>
<%=user.getUserName() %>
// 动作标签 之 获得属性的标签
// 动作标签 之 设置属性的标签
<jsp:setProperty name="" property="" value=""/>
<%String userName = request.getParameter();
String age = request.getParameter();
User user = new User();
%>
<jsp:setProperty name="user" property="userName" value="<%=userName%>"/>
<%
UserManager m = new UserManagerImpl();
m.addUserInfo(user);
%>
<%
User user = request.getAttribute("user");
%>
<%=user.getUserName() %>
格式:${表达式语言}
${user.userName}
${user["userName"]}
${requestScope.user["userName"]}
${sessionScope|applicationScope|pageScope}
head.jsp
${sessionScope.}
<%
Cookie[] cs = request.getCookies();
for(Cookie c:cs)
{
if("colorName".equals(c.getName()))
{
%>
<%=c.getValue() %>
<%
break;
}
}
%>
<%
String str = request.getHeader("User-Agent");
%>
<%%>
${header["User-Agent"]}
2.jsp
<%
String str = request.getMethod();
String str2 = request.getQueryString();
%>
JSTL:Java Standard Tag Libary
Java的标准标签库
自定子标签。
要在jsp文件的开头出写如下语句,表示引入标签
<%
int i=10;
User user = new User();
user.setName("zhangsan");
user.setAge(20);
//session.setAttribute("user",user);
%>
<c:set var="i" value="10"/>
<c:set var="user" value="${pageScope.user}" scope="session"/>
User request.setAttribute("user",user);
<td>${requestScope.user.userName}</td>
<td>
<c:if test="${requestScope.user.sex eq 1}">
Male</c:if>
Female
</c:if>
</td>
<c:choose>
<c:when test="${requestScope.user.sex eq 1}">
Male
</c:when>
<c:otherwise>
Female
</c:otherwise>
</c:choolse>