• 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>


    运行截图:

     

  • 相关阅读:
    【Eolinker使用】接口测试--如何解决接口重定向
    ExtJS按钮
    Redis-消费模式
    Redis笔记教程
    C++中this指针的用法
    C — 对C语言的认识
    你还在迷茫什么
    2019-2020-1 20199324《Linux内核原理与分析》第四周作业
    2019-2020-1 20199324《Linux内核原理与分析》第三周作业
    2019-2020-1 20199324《Linux内核原理与分析》第二周作业
  • 原文地址:https://www.cnblogs.com/zyj3955/p/13986847.html
Copyright © 2020-2023  润新知