zoukankan      html  css  js  c++  java
  • Javabean使用实例

    1.login.jsp

    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <!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=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <form name="User" action="loginuser.jsp?mypass=417020" method="post">
    <table>
    <tr>
    <td>姓名:</td>
    <td><input type="text" name="username"></td>
    </tr>
    <tr>
    <td>密码:</td>
    <td><input type="password" name="password"></td>
    </tr>
    <tr>
    <td><input type="submit" value="登录"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    2.loginuser,jsp

    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <!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=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <jsp:useBean id="myUsers" class="javabean.Users"></jsp:useBean>
    <h1>setProperty动作元素</h1>
    <br>
    <!-- 根据表单匹配部分属性 ,且使用request对象参数值赋值 -->
    <jsp:setProperty property="password" name="myUsers" param="mypass"/>
    <%
    request.setCharacterEncoding("utf-8");
    %>
    用户名:<%=myUsers.getUsername() %><br>
    密码:<%=myUsers.getPassword() %><br>
    <!-- 根据表单匹配部分属性 -->
    <jsp:setProperty property="username" name="myUsers"/>
    <%
    request.setCharacterEncoding("utf-8");
    %>
    用户名:<%=myUsers.getUsername() %><br>
    密码:<%=myUsers.getPassword() %><br>
    <!-- 根据表单自动匹配所有属性 -->
    <jsp:setProperty property="*" name="myUsers"/>
    <%
    request.setCharacterEncoding("utf-8");
    %>
    用户名:<%=myUsers.getUsername() %><br>
    密码:<%=myUsers.getPassword() %><br>

    <%--使用getProperty方法获取属性值 --%>
    用户名:<jsp:getProperty property="username" name="myUsers"/><br>
    密码:<jsp:getProperty property="password" name="myUsers"/><br>
    </body>
    </html>


    运行截图:

     

  • 相关阅读:
    【数学建模】—优秀论文(一)
    【数学建模】—论文排版
    【Linux学习】—第8章linux编程
    【Linux学习】—文件权限和目录配置
    【ESP8266学习】(一)
    【OpenCV】——b站达尔闻
    【Linux学习】——Shell编程基础
    【数学建模】——模拟退火算法(SAA)
    react 开发中火狐,Safari浏览器嵌套iframe显示空白
    element ui dataPicker 日期范围限制
  • 原文地址:https://www.cnblogs.com/zyj3955/p/13986847.html
Copyright © 2011-2022 走看看