JavaBean技术

论坛 期权论坛 脚本     
已经匿名di用户   2022-5-29 19:34   2213   0





通过非可视化的JavaBean,封装邮地址对象,通过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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="result.jsp" method="post">
<table align="center" width="300" border="1" height="150">
<tr>
<td colspan="2" align="center">
<b>邮箱认证系统</b>
</td>
</tr>
<tr>
<td align="right">邮箱地址:</td>
<td><input type="text" name="mailAdd"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" />
</td>
</tr>
</table>
</form>
</body>
</html>











<%@ 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">


<%@page import="com.lyq.bean.Email"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<%
// 获取邮箱地址
String mailAdd = request.getParameter("mailAdd");
// 实例化Email,并对mailAdd赋值
Email email = new Email(mailAdd);
// 判断是否是标准的邮箱地址
if(email.isEamil()){
out.print(mailAdd + " <br>是一个标准的邮箱地址!<br>");
}else{
out.print(mailAdd + " <br>不是一个标准的邮箱地址!<br>");
}
%>
<a href="index.jsp">返回</a>
</div>
</body>
</html>

















//



<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="produce" class="com.lyq.bean.Produce"></jsp:useBean>
<div>
<ul>
<li>
商品名称:<jsp:getProperty property="name" name="produce"/>
</li>
<li>
价格:<jsp:getProperty property="price" name="produce"/>
</li>
<li>
数量:<jsp:getProperty property="count" name="produce"/>
</li>
<li>
厂址:<jsp:getProperty property="factoryAdd" name="produce"/>
</li>
</ul>
</div>
</body>
</html>













//






<%@ 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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="reg.jsp" method="post">
<table align="center" width="400" height="200" border="1">
<tr>
<td align="center" colspan="2" height="40">
<b>添加用户信息</b>
</td>
</tr>
<tr>
<td align="right">姓 名:</td>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<td align="right">年 龄:</td>
<td>
<input type="text" name="age">
</td>
</tr>
<tr>
<td align="right">性 别:</td>
<td>
<input type="text" name="sex">
</td>
</tr>
<tr>
<td align="right">住 址:</td>
<td>
<input type="text" name="add">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="添 加">
</td>
</tr>
</table>
</form>
</body>
</html>















<%@ 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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%request.setCharacterEncoding("UTF-8");%>
<jsp:useBean id="person" class="com.lyq.bean.Person" scope="page">
<jsp:setProperty name="person" property="*"/>
</jsp:useBean>
<table align="center" width="400">
<tr>
<td align="right">姓 名:</td>
<td>
<jsp:getProperty property="name" name="person"/>
</td>
</tr>
<tr>
<td align="right">年 龄:</td>
<td>
<jsp:getProperty property="age" name="person"/>
</td>
</tr>
<tr>
<td align="right">性 别:</td>
<td>
<jsp:getProperty property="sex" name="person"/>
</td>
</tr>
<tr>
<td align="right">住 址:</td>
<td>
<jsp:getProperty property="add" name="person"/>
</td>
</tr>
</table>
</body>
</html>














//





<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>XX新闻发布系统</title>
</head>
<body>
<form action="release.jsp" method="post">
<table align="center" width="450" height="260" border="1">
<tr>
<td align="center" colspan="2" height="40" >
<b>新闻发布</b>
</td>
</tr>
<tr>
<td align="right">标 题:</td>
<td>
<input type="text" name="title" size="30">
</td>
</tr>
<tr>
<td align="right">内 容:</td>
<td>
<textarea name="content" rows="8" cols="40"></textarea>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="发 布">
</td>
</tr>
</table>
</form>
</body>
</html>














<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>发布结果</title>
<style type="text/css">
#container{
width: 450px;
border: solid 1px;
padding: 20px;
}
#title{
font-size: 16px;
font-weight: bold;
color: #3399FF;
}
#content{
font-size: 12px;
text-align: left;
}
</style>
</head>
<body>
<jsp:useBean id="news" class="com.lyq.bean.News"></jsp:useBean>
<jsp:useBean id="encoding" class="com.lyq.bean.CharactorEncoding"></jsp:useBean>
<jsp:setProperty property="*" name="news"/>
<div align="center">
<div id="container">
<div id="title">
<%= encoding.toString(news.getTitle())%>
</div>
<hr>
<div id="content">
<%= encoding.toString(news.getContent())%>
</div>
</div>
</div>
</body>
</html>


















//




<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>电子时钟</title>
<style type="text/css">
#clock{
width:420px;
height:80px;
background:#E0E0E0;
font-size: 25px;
font-weight: bold;
border: solid 5px orange;
padding: 20px;
}
#week{
padding-top:15px;
color: #0080FF;
}
</style>
<meta http-equiv="Refresh" content="1">
</head>
<body>
<jsp:useBean id="date" class="com.lyq.bean.DateBean" scope="application"></jsp:useBean>
<div align="center">
<div id="clock">
<div id="time">
<jsp:getProperty property="dateTime" name="date"/>
</div>
<div id="week">
<jsp:getProperty property="week" name="date"/>
</div>
</div>
</div>
</body>
</html>












//


创建将字符串转换成数组的JavaBean,实现对”问卷调查"表单中复选框的数值的处理






<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>调查问卷</title>
</head>


<body>
<form action="reg.jsp" method="post">
<div>
<h1>调查问卷</h1>
<hr/>
<ul>
<li>你经常用哪些编程语言开发程序:</li>
<li>
<input type="checkbox" name="languages" value="JAVA">JAVA
<input type="checkbox" name="languages" value="PHP">PHP
<input type="checkbox" name="languages" value=".NET">.NET
<input type="checkbox" name="languages" value="VC++">VC++
</li>
</ul>
<ul>
<li>你目前所掌握的技术:</li>
<li>

<input type="checkbox" name="technics" value="HTML">HTML
<input type="checkbox" name="technics" value="JAVA BEAN">JAVA BEAN
<input type="checkbox" name="technics" value="JSP">JSP
<input type="checkbox" name="technics" value="SERVLET">SERVLET
</li>
</ul>
<ul>
<li>在学习中哪一部分感觉有困难:</li>
<li>
<input type="checkbox" name="parts" value="JSP">JSP
<input type="checkbox" name="parts" value="STRUTS">STRUTS
</li>
</ul>
&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="提 交">
</div>
</form>
</body>
</html>










<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>调查结果</title>
</head>


<body>
<jsp:useBean id="paper" class="com.lyq.bean.Paper"></jsp:useBean>
<jsp:useBean id="convert" class="com.lyq.bean.Convert"></jsp:useBean>
<jsp:setProperty property="*" name="paper"/>
<div>
<h1>调查结果</h1>
<hr/>
<ul>
<li>
你经常使用的编程语言:<%= convert.arr2Str(paper.getLanguages()) %> 。
</li>
<li>
你目前所掌握的技术:<%= convert.arr2Str(paper.getTechnics()) %> 。
</li>
<li>
在学习中感觉有困难的部分:<%= convert.arr2Str(paper.getParts()) %> 。
</li>
</ul>
</div>
</body>
</html>












//




编写一个封装学生信息的JavaBean对象,在index.jsp页面中调用该对象,并将学生信息输出到封面中










//






编写一个封装用户信息的JavaBean对象,通过操作JavaBean的动作意识,输出用户的注册信息




<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>用户注册</title>
</head>
<body>


<form action="reg.jsp" method="post">
<table align="center" width="450">
<tr>
<td align="center" colspan="2">
<h2>用户注册</h2>
<hr>
</td>
</tr>
<tr>
<td align="right">用户名:</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td align="right">性别:</td>
<td>
<input type="radio" name="sex" value="男" checked="checked">男
<input type="radio" name="sex" value="女">女
</td>
</tr>
<tr>
<td align="right">QQ号码:</td>
<td><input type="text" name="qq" /></td>
</tr>
<tr>
<td align="right">E-Mail地址:</td>
<td><input type="text" name="mail" /></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="注 册">
</td>
</tr>
</table>
</form>
</body>
</html>















<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>注册信息</title>
</head>
<body>
<%request.setCharacterEncoding("GB18030"); %>
<jsp:useBean id="user" class="com.lyq.bean.User">
<jsp:setProperty property="*" name="user"/>
</jsp:useBean>
<table align="center" width="400">
<tr>
<td align="right">姓 名:</td>
<td>
<jsp:getProperty property="name" name="user"/>
</td>
</tr>
<tr>
<td align="right">密 码:</td>
<td>
<jsp:getProperty property="password" name="user"/>
</td>
</tr>
<tr>
<td align="right">性 别:</td>
<td>
<jsp:getProperty property="sex" name="user"/>
</td>
</tr>
<tr>
<td align="right">QQ号码:</td>
<td>
<jsp:getProperty property="qq" name="user"/>
</td>
</tr>
<tr>
<td align="right">E-Mail地址:</td>
<td>
<jsp:getProperty property="mail" name="user"/>
</td>
</tr>
</table>
</body>
</html>














//






编写一个页面访问计数器的JavaBean,在index.jsp页面中通过JSP动作标签实例化该对象,并将其放置于application范围中,实现访问计数器








<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>计数器</title>
</head>
<body>
<jsp:useBean id="counter" class="com.lyq.bean.Counter"></jsp:useBean>
<h2>
欢迎光临,你是第
<jsp:getProperty property="count" name="counter"/>
位来访者。
</h2>
</body>
</html>
















//











//
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP