过滤器和监听器

来源:互联网 发布:回到2005年txt下载知轩 编辑:程序博客网 时间:2024/06/06 16:42

////////////////////////////////////////////////////////////////////////////////////////////////



实现网站计数器



<%@ 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>人数统计</title>
</head>
<body>
<h2>
欢迎光临,<br>
您是本站的第【 
<%=application.getAttribute("count") %>
】位访客!
</h2>
</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>添加图书信息</title>
</head>
<body>
<form action="AddServlet" method="post">
<table align="center" border="1" width="350">
<tr>
<td class="2" align="center" colspan="2">
<h2>添加图书信息</h2>
</td>
</tr>
<tr>
<td align="right">图书编号:</td>
<td>
<input type="text" name="id">
</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="author">
</td>
</tr>
<tr>
<td align="right">价  格:</td>
<td>
<input type="text" name="price">
</td>
</tr>
<tr>
<td class="2" align="center" colspan="2">
<input type="submit" value="添 加">
</td>
</tr>
</table>
</form>
</body>
</html>











////////////////////////////////////////////////////////////////////////////////////////////////



应用Servlet监视器统计在线人数






<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>使用监听查看在线用户</title>
</head>
<script language="javascript">
function checkEmpty(form){
for(i=0;i<form.length;i++){
if(form.elements[i].value==""){
alert("表单信息不能为空");
return false;
}
}
}
</script>
<link href="css/style.css" rel="stylesheet" type="text/css">
<body>
<div align="center">
  <table width="506" height="170" border="0" cellpadding="0" cellspacing="0" background="image/background1.jpg">
    <tr>
      <td align="center">
   <form name="form" method="post" action="showUser.jsp" onSubmit="return checkEmpty(form)">
    <input type="text" name="user"><br><br>
    <input type="submit" name="Submit" value="登录">
  </form>
 
 
 
 </td>
    </tr>
  </table>
</div>
</body>
</html>









<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%
         session.invalidate();
 out.println("<script>parent.location.href='index.jsp';</script>");
%>










统计在线人数界面



<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="com.listener.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>使用监听查看在线用户</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<%
UserInfoList list=UserInfoList.getInstance();
UserInfoTrace ut=new UserInfoTrace();
String name=request.getParameter("user");
ut.setUser(name);
session.setAttribute("list",ut);
list.addUserInfo(ut.getUser());
session.setMaxInactiveInterval(10);
%>
<body>
<div align="center">




<table width="506" height="246" border="0" cellpadding="0" cellspacing="0" background="image/background2.jpg">
  <tr>
    <td align="center"><br>
 
 <textarea rows="8" cols="20">
<%
Vector vector=list.getList();
if(vector!=null&&vector.size()>0){
for(int i=0;i<vector.size();i++){
  out.println(vector.elementAt(i));
}
}
%>
</textarea><br><br>
 <a href="loginOut.jsp">返回</a>
 
 </td>
  </tr>
</table>
</div>
</body>
</html>










////////////////////////////////////////////////////////////////////////////////////////////////




JSP与Servlet实现用户注册




<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>用户注册</title>
<link href="css/style.css" type="text/css">
<style type="text/css">
body{
margin: 0px;font-size: 12px;
}
.box{
border: 1px solid #D1DEB2; width: 150px; height: 20px;
}
.div1{
background-image: url(images/bg.jpg);
height: 600px;
width: 803px;
padding-left:20px;
padding-top:220px;
text-align:left;
}
</style>
<script type="text/javascript">
    function reg(form){
        if(form.username.value == ""){
        alert("用户不能为空!");
        return false;
        }
        if(form.password.value == ""){
        alert("密码不能为空!");
        return false;
        }
        if(form.repassword.value == ""){
        alert("确认密码不能为空!");
        return false;
        }
        if(form.password.value != form.repassword.value){
        alert("两次密码输入不一致!");
        return false;
        }
        if(form.question.value == ""){
        alert("密码找回问题不能为空!");
        return false;
        }
        if(form.answer.value == ""){
        alert("密码找回答案不能为空!");
        return false;
        }
        if(form.email.value == ""){
        alert("电子邮箱不能为空!");
        return false;
        }
    }
   </script>
</head>
<body>
<div align="center">
<div class="div1">
<form action="SaveServlet" method="post" onSubmit="return reg(this);">
<table align="center" border="0" width="500">
<tr>
<td align="right" width="30%" size ="9pt">用户名:</td>
<td><input type="text" name="username" class="box"></td>
</tr>
<tr>
<td align="right">密 码:</td>
<td><input type="password" name="password" class="box"></td>
</tr>
<tr>
<td align="right">确认密码:</td>
<td><input type="password" name="repassword" class="box"></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">密码找回问题:</td>
<td><input type="text" name="question" class="box"></td>
</tr>
<tr>
<td align="right">密码找回答案:</td>
<td><input type="text" name="answer" class="box"></td>
</tr>
<tr>
<td align="right">邮 箱:</td>
<td><input type="text" name="email" class="box"></td>
</tr>
<tr>
<td colspan="2" align="center" height="40">
<input type="submit" value="注 册">
<input type="reset" value="重 置">
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
















////////////////////////////////////////////////////////////////////////////////////////////////


应用Servlet实现文件上传



<%@ 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="UploadServlet" enctype="multipart/form-data" method ="post" >
    选择文件<input type="file" name="file1" id= "file1"/>   
    <input type="submit" name="upload" value="上传" />
 </form>
</body>
</html>











////////////////////////////////////////////////////////////////////////////////////////////////


<%@ page language="java" contentType="text/html" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>意见反馈</title>
<style type="text/css">
body {
margin: 0px;
font-size: 12px;
}
td{
font-size: 12px;
}
.div1{
width: 1003px;
height: 707px;
background-image: url("images/bg.jpg");
}
.div2{
width: 500px;
margin-top:245px;
margin-left:180px;
text-align:left;
}
.tl{
width: 500px;
height: 20px;
font-weight: bold;
background: #A3C0C6;
padding: 5px;
}
.ct{
width: 500px;
padding-left: 30px;
padding-top: 5px;
padding-bottom: 5px;
}
.tt{
margin-left:5px;
width: 70px;
background: #A3C0C6;
padding: 5px;
font-weight: bold;
font-size: 13px;
}
</style>
</head>


<body>
<div align="center">
<div class="div1">
<div class="div2">
<%
String title = (String)request.getAttribute("title");
String content = (String)request.getAttribute("content");
if(title != null && !title.isEmpty()){
out.println("<span class='tl'>" + title + "</span>");
}
if(content != null && !content.isEmpty()){
out.println("<span class='ct'>" + content + "</span>");
}
%>
<span class="tl">谢谢你们</span>
<span class="ct">你们的公司服务态度非常好,谢谢你们!</span>
<span class="tl">谢谢你们</span>
<span class="ct">你们的公司服务态度非常好<br>但部分客服服务态度还要加强!</span>
<form action="MessageServlet" method="post">
<span class="tt">意见反馈</span>
<table border="0" width="500" align="center">
<tr>
<td align="right">标 题:</td>
<td><input type="text" name="title" size="30"></td>
</tr>
<tr>
<td align="right">内 容:</td>
<td>
<textarea rows="5" cols="40" name="content"></textarea>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="提 交">
</td>
</tr>
</table>
</form>
</div>
</div>
</div>

</body>
</html>















//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

利用监听器使服务器端免登入




<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>利用监听使服务器端机器免登录</title>
</head>
<%


String login=(String)request.getAttribute("login");
if(login.equals("true")){
response.sendRedirect("show.htm");
}




%>
<body><div align="center">


 <table width="335" height="225">
   <tr>
     <td background="leftsearch.gif" align="center">
 <form name="form1" method="post" action="show.htm">
   <input type="submit" name="Submit" value="登录">
 </form>
 
</td>
   </tr>
 </table>
</div>
</body>
</html>











<!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=gb2312">
<title>利用监听使服务器端机器免登录</title>
</head>


<body>
<div align="center">
  <table width="335" height="225">
    <tr>
      <td background="leftsearch.gif" align="center">这是你要访问的页面<br>
如果您远程访问一定去过登录页面吧。</td>
    </tr>
  </table>
</div>
</body>
</html>












//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


1 0
原创粉丝点击