JSP的setProperty的使用方法
jsp的setproperty的使用方法
一 介紹
<jsp:setproperty>作用
給已經實例化的javabean對象的屬性賦值,一共有四種形式。
二 四種形式
三 實例
1、login.jsp
<%@ page language="java" import="java.util.*" contenttype="text/html; charset=utf-8" %> <% 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%>" rel="external nofollow" rel="external nofollow" > <title>my jsp 'login.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" rel="external nofollow" rel="external nofollow" > --> </head> <body> <h1>系統登錄</h1> <hr> <form name="loginform" action="dologin.jsp?mypass=999999" method="post"> <table> <tr> <td>用戶名:</td> <td><input type="text" name="username" value=""/></td> </tr> <tr> <td>密碼:</td> <td><input type="password" name="password" value=""/></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="登錄"/></td> </tr> </table> </form> </body> </html>
2、dologin.jsp
<%@ page language="java" import="java.util.*" contenttype="text/html; charset=utf-8"%> <% 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%>" rel="external nofollow" rel="external nofollow" > <title>my jsp 'dologin.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" rel="external nofollow" rel="external nofollow" > --> </head> <body> <jsp:usebean id="myusers" class="com.po.users" scope="page"/> <h1>setproperty動作元素</h1> <hr> <!--根據表單自動匹配所有的屬性 --> <%-- <jsp:setproperty name="myusers" property="*"/> --%> <!--根據表單匹配所有部分的屬性 --> <%-- <jsp:setproperty name="myusers" property="username"/> --%> <!--根表單無關,通過手工賦值給屬性 --> <%-- <jsp:setproperty name="myusers" property="username" value="lisi"/> <jsp:setproperty name="myusers" property="password" value="888888"/> --%> <!--通過url傳參數給屬性賦值 --> <jsp:setproperty name="myusers" property="username"/> <jsp:setproperty name="myusers" property="password" param="mypass"/> <!-- 使用傳統的表達式方式來獲取用戶名和密碼 --> 用戶名:<%=myusers.getusername() %><br> 密碼:<%=myusers.getpassword() %><br> <br> <br> </body> </html>
四 運行結果
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
- jsp+servlet實現文件上傳與下載功能
- EJB3.0部署消息驅動Bean拋javax.naming.NameNotFoundException異常
- 在JSP中使用formatNumber控制要顯示的小數位數方法
- 秒殺系統Web層設計的實現方法
- 將properties文件的配置設置為整個Web應用的全局變量實現方法
- JSP使用過濾器防止Xss漏洞
- 在JSP頁面中動態生成圖片驗證碼的方法實例
- 詳解JSP 內置對象request常見用法
- 使用IDEA編寫jsp時EL表達式不起作用的問題及解決方法
- jsp實現局部刷新頁面、異步加載頁面的方法
- Jsp中request的3個基礎實踐
- JavaServlet的文件上傳和下載實現方法
- JSP頁面的靜態包含和動態包含使用方法