SpringMVC-基礎篇-前臺

list

============================================================================

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    
<!-- 沒有struts時只能用jsp標籤 --> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>

<!-- 循環迭代 -->
<c:forEach items="${key}" var="myu">


<!-- 普通方式“?”傳參 -->
<%-- ${myu.userName} &nbsp;&nbsp;&nbsp;&nbsp;${myu.password} <a href="#">change</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="del?userName =  ${myu.userName}">delete</a><br/> --%>


<!-- rest風格傳參 -->
${myu.userName} &nbsp;&nbsp;&nbsp;&nbsp;${myu.password} <a href="one/${myu.userName}">change</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="del/${myu.userName}">delete</a><br/>
</c:forEach>

</body>
</html>


================================================================================================


add

===============================================================================================

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8">
<title>Insert title here</title>
</head>
<body>

<!-- 方法1 -->
<!-- 使用普通的表單控件和servlet取值 -->
<!-- <form action="add" method="post">
用戶名:<input type="text" name="userName"><br/>
密碼:<input type="password" name="password"><br/>
<input type="submit" value="submit"/><br/>
</form> -->



<!-- zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz -->



<!-- 方法2 -->
<!-- 使用spring自帶的表單控件 -->
<!-- 前臺控件數據要想和實體類屬性自動綁定的話
1:要用spring自己的標籤
2:控件名字要和實體類屬性的名字一致
3:modelAttribute的內容要和後臺controller方法參數的名字一致 -->
<sf:form action="add" modelAttribute="user" method="post">
<!-- path相當於控件的名字 -->
<sf:input path="userName"/><br/>
<sf:password path="password"/><br/>
<!-- 按鈕用普通控件的標籤,可以混合在一起用。 -->
<input type="submit" value="submit"/>
</sf:form>
</body>
</html>


=================================================================================


update


================================================================================

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8">
<title>Insert title here</title>
</head>
<body>

<sf:form  modelAttribute="user" method="post">
<!-- path相當於控件的名字 -->
<sf:input path="userName"/><br/>
<sf:password path="password"/><br/>
<!-- 按鈕用普通控件的標籤,可以混合在一起用。 -->
<input type="submit" value="submit"/>
</sf:form>
</body>
</html>


發佈了38 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章