AccessInBuildingSessionRemote.Java
package accessinbuilding;
import java.util.List;
import javax.ejb.Remote;
@Remote
public interface AccessInBuildingSessionRemote {
int findByNameOrCode(String name, int code);
void addAccess(String name, int code);
int findCountAct();
List getAllUsers();
void updateAct(int id, int act);
void addLog(int id, int act, String descr);
List getLogs();
void login(String login, String pwd);
String getToken();
}
Web-модуль:
Act.jsp
<%@page contentType="text/html" pageEncoding="utf-8"%>
<%@page import="javax.naming.*, accessinbuilding.*" %>
<%@page errorPage="err.jsp"%>
<%!
AccessInBuildingSessionRemote ejbRef;
%>
<%
InitialContext ic = new InitialContext();
ejbRef = (AccessInBuildingSessionRemote)ic.lookup("accessinbuilding.AccessInBuildingSessionRemote");
int cnt = ejbRef.findCountAct();
%>
<%=cnt%>
Add.jsp
<%@page contentType="text/html" pageEncoding="utf-8"%>
<%@page import="javax.naming.*, accessinbuilding.*" %>
<%@page errorPage="err.jsp"%>
<%!
AccessInBuildingSessionRemote ejbRef;
%>
<%
InitialContext ic = new InitialContext();
ejbRef = (AccessInBuildingSessionRemote)ic.lookup("accessinbuilding.AccessInBuildingSessionRemote");
ejbRef.addAccess( request.getParameter("name"), Integer.parseInt(request.getParameter("code")) );
%>
done
Err.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
error
Find.jsp
<%@page contentType="text/html" pageEncoding="utf-8"%>
<%@page import="javax.naming.*, accessinbuilding.*" %>
<%@ page errorPage="err.jsp"%>
<%!
AccessInBuildingSessionRemote ejbRef;
%>
<%
InitialContext ic = new InitialContext();
ejbRef = (AccessInBuildingSessionRemote)ic.lookup("accessinbuilding.AccessInBuildingSessionRemote");
int findID = ejbRef.findByNameOrCode( request.getParameter("name"), Integer.parseInt(request.getParameter("code")) );
%>
<%=findID%>
Index.jsp
<%@page contentType="text/html" 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=windows-1251">
<title>Система учета прохода в здание</title>
<link href="css.css" type="text/css" rel="stylesheet" />
<link href="css/jquery-ui-1.9.1.custom.css" type="text/css" rel="stylesheet">
<script src="jquery-1.8.2.min.js"></script>
<script src="jquery-ui.js"></script>
<script type='text/javascript'>jQuery.noConflict();</script>
<script src="js.js"></script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="700" align="center" class="body">
<tr>
<td>
<h1>Система учета прохода в здание</h1>
<div align="right" class="add_b">
<div align="right">Добавить нового пользователя</div>
</div>
<form action="add.jsp" method="post" enctype="multipart/form-data" class="add_form">
Имя<sup>*</sup>: <input type="text" name="name" id="add_name" value="" />
Код: <input type="text" name="code" id="add_code" value="" />
<input type="submit" value="Добавить пользователя" class="add" /><span class="add_load"> </span>
<div class="add_err"></div>
</form>
<form action="find.jsp" method="post" enctype="multipart/form-data" class="find_form">
Имя<sup>*</sup>: <input type="text" name="name" id="find_name" value="" />
Код: <input type="text" name="code" id="find_code" value="" />
<input type="submit" value="Найти" class="find" /><span class="find_load"> </span>
<div class="find_err">Поиск пользователя, например: <span>Иванов Иван</span> </div>
</form>
<br>
<div class="cnt_act"></div>
<div class="users"></div>
<div align="right"><br><span class="log"></span></div>
</td>
</tr>
</table>
</body>
</html>
Logs.jsp
<%@page contentType="text/html" pageEncoding="utf-8"%>
<%@page import="javax.naming.*, java.util.List, java.util.Date, accessinbuilding.*" %>
<%@page errorPage="err.jsp"%>
<%!
AccessInBuildingSessionRemote ejbRef;
%>
<%
InitialContext ic = new InitialContext();
ejbRef = (AccessInBuildingSessionRemote)ic.lookup("accessinbuilding.AccessInBuildingSessionRemote");
List logs = ejbRef.getLogs( );
int sz = logs.size(), id = 0;
Date date;
String ret = "", descr = "", bgl = "", name = "";
if( sz > 0 ) {
ret = "<br><table width='100%' border='0' cellspacing='0' cellpadding='6'>";
ret += "<tr bgcolor='#68d7f8' class='ubg'>";
ret += "<th width='30' align='right'>№</th>";
ret += "<th width='170' align='left'>Дата</th>";
ret += "<th align='left'>Имя</th>";
ret += "<th align='left'>Лог</th>";
ret += "</tr>";
for(int i=0; i < sz; i++) {
id = ((Log)logs.get(i)).getId();
date = ((Log)logs.get(i)).getDate();
name = ((Log)logs.get(i)).getAssignedAccess().getName();
descr = ((Log)logs.get(i)).getDescr();
bgl = ( (i%2) > 0 ? " bgcolor='#d7e1f2'" : " bgcolor='#eff2f7'" );
ret += "<tr"+bgl+">"+
"<td align='right'>"+ (i+1) +"</td>"+
"<td>"+ date +"</td>"+
"<td>"+ name +"</td>"+
"<td>"+ descr +"</td>"+
"</tr>";
}
ret += "</table>";
}
%>
<%=ret%>
Update_act.jsp
<%@page contentType="text/html" pageEncoding="utf-8"%>
<%@page import="javax.naming.*, accessinbuilding.*" %>
<%@page errorPage="err.jsp"%>
<%!
AccessInBuildingSessionRemote ejbRef;
%>
<%
InitialContext ic = new InitialContext();
ejbRef = (AccessInBuildingSessionRemote)ic.lookup("accessinbuilding.AccessInBuildingSessionRemote");
ejbRef.updateAct( Integer.parseInt(request.getParameter("id")), Integer.parseInt(request.getParameter("act")) );
ejbRef.addLog( Integer.parseInt(request.getParameter("id")), Integer.parseInt(request.getParameter("act")), "" );
%>
done
Users.jsp
<%@page contentType="text/html" pageEncoding="utf-8"%>
<%@page import="javax.naming.*, java.util.List, accessinbuilding.*" %>
<%@page errorPage="err.jsp"%>
<%!
AccessInBuildingSessionRemote ejbRef;
%>
<%
InitialContext ic = new InitialContext();
ejbRef = (AccessInBuildingSessionRemote)ic.lookup("accessinbuilding.AccessInBuildingSessionRemote");
List access = ejbRef.getAllUsers( );
int sz = access.size(), act = 0, id = 0, code = 0;
String ret = "", name = "", stat = "", bgl = "";
if( sz > 0 ) {
ret = "<br><table width='100%' border='0' cellspacing='0' cellpadding='6'>";
ret += "<tr bgcolor='#68d7f8' class='ubg'>";
ret += "<td width='30' align='right'>№</td>";
ret += "<td width='50'>Код</td>";
ret += "<td>ФИО</td>";
ret += "<td width='200' align='center'>Статус</td>";
ret += "</tr>";
for(int i=0; i < sz; i++) {
id = ((Access)access.get(i)).getId();
code = ((Access)access.get(i)).getCode();
name = ((Access)access.get(i)).getName();
act = ((Access)access.get(i)).getAct();
if( act > 0 ) {
bgl = ( (i%2) > 0 ? " bgcolor='#a3eb6f'" : " bgcolor='#f0fbe8'" );
} else {
bgl = ( (i%2) > 0 ? " bgcolor='#d7e1f2'" : " bgcolor='#eff2f7'" );
}
stat = "<div class='radio'>" +
"<input type='radio' name='radio_"+id+"' id='radio_"+id+"_0' value='0'"+ ( act == 0 ? " checked" : "" ) +" /><label class='status' for='radio_"+id+"_0'>нету</label>" +
"<input type='radio' name='radio_"+id+"' id='radio_"+id+"_1' value='1'"+ ( act > 0 ? " checked" : "" ) +" /><label class='status' for='radio_"+id+"_1'>в здании</label>" +
"</div>";
ret += "<tr"+bgl+">"+
"<td align='right'>"+ (i+1) +"</td>"+
"<td>"+ code +"</td>"+
"<td>"+ name +"</td>"+
"<td align='center'>"+ stat +"</td>"+
"</tr>";
}
ret += "</table>";
}
%>
<%=ret%>
Css.css
* { font:14px Arial; }
html, body { margin:0px; padding:0px; }
html { background:#09217d repeat url('http://127.0.0.1:8080/AccessInBuilding-war/img/bg.jpg'); }
body { background:repeat-x top url('http://127.0.0.1:8080/AccessInBuilding-war/img/bg_top.jpg'); min-height: 476px; }
.body {
background: #ffffff;
padding: 20px;
padding-top: 10px;
-webkit-border-bottom-right-radius: 7px;
-webkit-border-bottom-left-radius: 7px;
-moz-border-radius-bottomright: 7px;
-moz-border-radius-bottomleft: 7px;
border-bottom-right-radius: 7px;
border-bottom-left-radius: 7px;
-webkit-box-shadow: 0px 0px 10px 3px rgba(0, 0, 0, 0.7);
box-shadow: 0px 0px 10px 3px rgba(0, 0, 0, 0.7);
}
h1 { font-size: 22px; }
.add_load, .find_load { background: no-repeat center center url('http://127.0.0.1:8080/AccessInBuilding-war/img/loading.gif'); display: none; }
.add_b { position: relative; }
.add_b div {
margin-top: -42px;
width:185px;
padding:5px;
font-size: 11px;
color:#ffffff;
background: #68d7f8 no-repeat 5px 4px url('http://127.0.0.1:8080/AccessInBuilding-war/img/add.png');
margin-bottom: 15px;
border:1px solid #1c8dff;
cursor: pointer;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.add_b div:hover, .add_b div.show { background-color:#ed7500; background-position:5px -96px; border-color:#9b4d00; }
.add_form {
display: none;
padding: 15px;
background: #68d7f8;
margin-bottom: 10px;
border-top: 1px solid #ed7500;
border-bottom: 1px solid #ed7500;
-webkit-border-radius: 7px;
-moz-border-radius: 7px;
border-radius: 7px;
}
.add_form.add { background: #a3eb6f; }
.find_form {
display: block;
padding: 10px 26px 10px 8px;
background: url('http://127.0.0.1:8080/AccessInBuilding-war/img/find.png') no-repeat 100% 50% #FC0;
}
.find_err, .find_err * { font-size: 12px; }
.find_err span { border-bottom: 1px dashed; cursor:pointer; }
form sup { color: red; }
input {
padding: 2px;
margin: 2px;
border:1px solid #cfcfcf;
background: #ebf0f6;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
input[type="text"] {
min-width: 160px;
}
input[type="submit"] {
min-width: 170px;
cursor: pointer;
}
.ubg, .ubg * { color: #ffffff; font-size: 18px; }
.cnt_act { text-align: center; }
.logs { display: none; }
.log { padding-top: 10px; color:#68d7f8; border-bottom: 1px dashed #68d7f8; cursor: pointer; }
.logs td { font-size: 11px; color:#666; }
Js.js
var timer;
jQuery(document).ready(function() {
function showMessage(id,msg) {
jQuery(id).hide().html(msg).show();
setTimeout(function(){ jQuery(id).fadeOut(500); }, 3000);
}
function updateCnt(obj) {
var _this = obj;
jQuery.get("act.jsp",{},function(data) {
data = jQuery.trim( data );
if( data > 0 ) txt = "В здании находится " + data + " человек(а)";
else txt = "В здании никого нет";
jQuery(_this).fadeOut(0).html(txt).fadeIn(1000);
});
}
function updateUsers(obj) {
var _this = obj;
jQuery.get("users.jsp",{},function(data) {
data = jQuery.trim( data );
if( data != "" ) {
jQuery(_this).fadeOut(0).html(data).fadeIn(1000);
jQuery(".radio").buttonset().refresh();
}
});
}
function updateLogs(obj) {
var _this = obj;
jQuery.get("logs.jsp",{},function(data) {
data = jQuery.trim( data );
if( data == "error" ) data = "Ошибка подключения к базе";
jQuery(_this).html(data);
});
}
jQuery(".add_b div").click(function(){
if( jQuery(this).is(".show") ) {
jQuery(this).removeClass("show");
jQuery(".add_form").slideUp().removeClass("add");
} else {
jQuery(this).addClass("show");
jQuery(".add_form").slideDown();
}
});
jQuery(".add").click(function() {
_this = this;
jQuery(".add_load").show();
name = jQuery("#add_name").val();
code = parseInt(jQuery("#add_code").val()) || 0;
jQuery(_this).parent().removeClass("add");
if( name != "" ) {
jQuery.get("add.jsp",{name:name,code:code},function(data) {
if( jQuery.trim( data ) == "done" ) {
showMessage(".add_err","Пользователь добавлен");
jQuery(_this).parent().addClass("add");
updateUsers(jQuery(".users").get(0));
updateLogs(jQuery(".log div").get(0));
} else {
showMessage(".add_err","Ошибка добавления");
}
jQuery(".add_load").hide();
});
} else {
showMessage(".add_err","Ошибка, не заполнено обязательное поле");
jQuery(".add_load").hide();
}
return false;
});
jQuery(".find").click(function() {
_this = this;
jQuery(".find_load").show();
var name = jQuery("#find_name").val();
code = parseInt(jQuery("#find_code").val()) || 0;
if( name != "" || code > 0 ) {
jQuery.get("find.jsp",{name:name,code:code},function(data) {
data = jQuery.trim( data );
if( data == "error" ) {
showMessage(".find_err","Ошибка доступа к базе");
} else if( data > 0 ) {
showMessage(".find_err",name + ", в базе есть");
jQuery(".find_load").hide();
} else if( data == 0 ){
showMessage(".find_err","Нет");
jQuery(".find_load").hide();
};
jQuery(".find_load").hide();
});
} else {
showMessage(".find_err","Ошибка, не заполненно не одно из полей");
jQuery(".find_load").hide();
}
return false;
});
jQuery(".find_err span").click(function() {
jQuery(".find_form #find_name").val(jQuery(this).text());
jQuery(".find").trigger("click");
});
jQuery(".cnt_act").each(function() {
updateCnt(this);
});
jQuery(".users").each(function() {
updateUsers(this);
});
jQuery( '.radio' ).buttonset();
jQuery(".radio span").live("click",function(){
row = jQuery(this).parent().attr("for").split('_');
jQuery.get("update_act.jsp",{id:parseInt(row[1]),act:parseInt(row[2])},function(data) {
updateCnt(jQuery(".cnt_act").get(0));
updateLogs(jQuery(".log div").get(0));
});
});
jQuery(".log").each(function() {
jQuery(this).html("Лог посещаемости<div class='logs'></div>");
});
jQuery(".log").live("click",function(){
div = jQuery('.logs',this);
if( div.is('.show') ) {
div.removeClass("show").slideUp('fast');
} else {
updateLogs(div);
div.addClass("show").slideDown();
}
});
});
Connect.jps
<%@page contentType="application/json" pageEncoding="utf-8"%><%@page import="javax.naming.*, java.util.Date, java.util.List, accessinbuilding.*" %><%@page errorPage="connect_error.jsp"%><%!
AccessInBuildingSessionRemote ejbRef;
%><%
String ret = "{\"error\":\"101\"}";
ejbRef = (AccessInBuildingSessionRemote)session.getAttribute("ejbRef");
if(ejbRef == null) {
InitialContext ic = new InitialContext();
ejbRef = (AccessInBuildingSessionRemote)ic.lookup("accessinbuilding.AccessInBuildingSessionRemote");
session.setAttribute("ejbRef", ejbRef);
}
String getToken = ejbRef.getToken();
if( request.getParameter("token") != null && getToken != "" && getToken.equals(request.getParameter("token")) ) {
String type = request.getParameter("type");
if( "act".equals(type) ) {
ret = "{\"cnt\":\"" + ejbRef.findCountAct() + "\"}";
} else if( "users".equals(type) ) {
List access = ejbRef.getAllUsers( );
int sz = access.size(), act = 0, id = 0, code = 0;
String name = "", stat = "", bgl = "";
if( sz > 0 ) {
ret = "<br><table width='100%' border='0' cellspacing='0' cellpadding='6'>";
ret += "<tr bgcolor='#68d7f8' class='ubg'>";
ret += "<td width='30' align='right'>№</td>";
ret += "<td width='50'>Код</td>";
ret += "<td>ФИО</td>";
ret += "<td width='200' align='center'>Статус</td>";
ret += "</tr>";
for(int i=0; i < sz; i++) {
id = ((Access)access.get(i)).getId();
code = ((Access)access.get(i)).getCode();
name = ((Access)access.get(i)).getName();
act = ((Access)access.get(i)).getAct();
if( act > 0 ) {
bgl = ( (i%2) > 0 ? " bgcolor='#a3eb6f'" : " bgcolor='#f0fbe8'" );
} else {
bgl = ( (i%2) > 0 ? " bgcolor='#d7e1f2'" : " bgcolor='#eff2f7'" );
}
stat = "<div class='radio'>" +
"<input type='radio' name='radio_"+id+"' id='radio_"+id+"_0' value='0'"+ ( act == 0 ? " checked" : "" ) +" /><label class='status' for='radio_"+id+"_0'>нету</label>" +
"<input type='radio' name='radio_"+id+"' id='radio_"+id+"_1' value='1'"+ ( act > 0 ? " checked" : "" ) +" /><label class='status' for='radio_"+id+"_1'>в здании</label>" +
"</div>";
ret += "<tr"+bgl+">"+
"<td align='right'>"+ (i+1) +"</td>"+
"<td>"+ code +"</td>"+
"<td>"+ name +"</td>"+
"<td align='center'>"+ stat +"</td>"+
"</tr>";
}
ret += "</table>";
ret = "{\"users\":\"" + ret + "\"}";
} else
ret = "{\"error\":\"404\"}";
} else if( "logs".equals(type) ) {
List logs = ejbRef.getLogs( );
int sz = logs.size(), id = 0;
Date date;
String descr = "", bgl = "", name = "";
if( sz > 0 ) {
ret = "<br><table width='100%' border='0' cellspacing='0' cellpadding='6'>";
ret += "<tr bgcolor='#68d7f8' class='ubg'>";
ret += "<th width='30' align='right'>№</th>";
ret += "<th width='170' align='left'>Дата</th>";
ret += "<th align='left'>Имя</th>";
ret += "<th align='left'>Лог</th>";
ret += "</tr>";
for(int i=0; i < sz; i++) {
id = ((Log)logs.get(i)).getId();
date = ((Log)logs.get(i)).getDate();
name = ((Log)logs.get(i)).getAssignedAccess().getName();
descr = ((Log)logs.get(i)).getDescr();
bgl = ( (i%2) > 0 ? " bgcolor='#d7e1f2'" : " bgcolor='#eff2f7'" );
ret += "<tr"+bgl+">"+
"<td align='right'>"+ (i+1) +"</td>"+
"<td>"+ date +"</td>"+
"<td>"+ name +"</td>"+
"<td>"+ descr +"</td>"+
"</tr>";
}
ret += "</table>";
ret = "{\"logs\":\"" + ret + "\"}";
} else
ret = "{\"error\":\"505\"}";
} else if( "add".equals(type) ) {
ejbRef.addAccess( request.getParameter("name"), Integer.parseInt(request.getParameter("code")) );
ret = "{\"data\":\"done\"}";
} else if( "find".equals(type) ) {
int findID = ejbRef.findByNameOrCode( request.getParameter("name"), Integer.parseInt(request.getParameter("code")) );
ret = "{\"data\":\""+findID+"\"}";
} else if( "update_act".equals(type) ) {
ejbRef.updateAct( Integer.parseInt(request.getParameter("id")), Integer.parseInt(request.getParameter("act")) );
ejbRef.addLog( Integer.parseInt(request.getParameter("id")), Integer.parseInt(request.getParameter("act")), "" );
ret = "{\"data\":\"done\"}";
} else ret = "{\"error\":\"303\"}";
} else if( request.getParameter("auth_login") != null && request.getParameter("auth_pwd") != null ) {
ejbRef.login(request.getParameter("auth_login"), request.getParameter("auth_pwd"));
getToken = ejbRef.getToken();
if( getToken != "" ) ret = "{\"token\":\"" + getToken + "\"}";
else ret = "{\"error\":\"202\"}";
}
%><%=ret%>
connect_error.jps
<%@page contentType="application/json" pageEncoding="utf-8"%>{"error":"error"}
- Так же в проекте были использованы JavaScript, библиотеки jQuery v1.8.2 и jQuery UI v1.9.1, CSS стили и CSS jQuery UI v1.9.1.