刚学JSP页面开发,把知识点整理一下。
-----------------------------------------------------------------------
JSP语法
http://www.runoob.com/jsp/jsp-syntax.html
<% 代码片段 %>
<% out.println("Hello World!"); %>
<%! 变量声明 %>
<%! int i = 0; %>
<%= 表达式 %>
<%= i %>
<%-- 注释 --%>
<%-- 注释内容不会被发送至浏览器 --%>
三种JSP指令
<%@ page ... %> 定义页面依赖属性
<%@ include ... %> 包含其他文件
<%@ taglib ... %> 声明要使用的标签库
EL表达式
http://www.runoob.com/jsp/jsp-expression-language.html
${expr}
JSP标准标签库(JSTL)
http://www.runoob.com/jsp/jsp-jstl.html
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<table>
<c:forEach var="user" items="${users}">
<tr>
<td>${user.id}</td>
<td>${user.name}</td>
</tr>
</c:forEach>
</table>
Spring’s JSP Tag Library
https://docs.spring.io/spring/docs/5.1.5.RELEASE/spring-framework-reference/web.html#mvc-view-jsp-tags
https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/spring-tld.html
新版文档不太好看,可以参考老版的。
<spring:url value="/users/${user.id}" var="userUrl" />
<spring:url value="/users/${user.id}/delete" var="deleteUrl" />
<spring:url value="/users/${user.id}/update" var="updateUrl" />
<button class="btn btn-danger" onclick="this.disabled=true;post(‘${deleteUrl}‘)">Delete</button>
Spring’s form tag library
https://docs.spring.io/spring/docs/5.1.5.RELEASE/spring-framework-reference/web.html#mvc-view-jsp-formtaglib
https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/spring-form-tld.html
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form modelAttribute="user" action="/users">
<table>
<tr>
<td>id:</td>
<td><form:input path="id"/></td>
</tr>
<tr>
<td>name:</td>
<td><form:input path="name"/></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Save Changes"/>
</td>
</tr>
</table>
</form:form>
原文地址:https://www.cnblogs.com/LikeVirgo/p/10412764.html