此Web项目要求我们实施一个电子商务网站。我试图在用户单击按钮后在jsp页面中打印由Mysql查询生成的表。我的小组负责人做了一些初步工作,但我不了解他使用的基础架构。似乎大多数东西都是在servlet中处理的。 在用户单击“打印销售报告”按钮后,我必须执行查询以生成销售报告表。 我该如何实施?
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="layout" tagdir="/WEB-INF/tags" %>
<%
String _token = (String) session.getAttribute("name");
request.setAttribute("name", _token);
boolean _isAdmin = (Boolean) session.getAttribute("e_type");
request.setAttribute("isAdmin", _isAdmin);
%>
<layout:template>
<jsp:attribute name="header">
</jsp:attribute>
<jsp:attribute name="footer">
</jsp:attribute>
<jsp:body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">BuyMe Admin</a>
<ul class="navbar-nav mr-auto" id="cnav"></ul>
</nav>
<div class="container" id="main-container">
<div class="row">
<h3>Email Correspondents</h3>
</div>
<div class="row">
<table class="table">
<thead>
<tr>
<th scope="col">From</th>
<th scope="col">To</th>
<th scope="col">Subject</th>
</tr>
</thead>
<tbody id="emailbody"></tbody>
</table>
</div>
</div>
<div>
<button id="sales-report-btn" class="btn my-2 my-sm-o">Print Sales Report</button>
</div>
<script type="text/javascript">
const email = `${name}`
function refresh() {
$.ajax({
url: '/PrinInfoProject/api/v1/emails?email=' + email,
method: 'GET'
})
.always(function(jqXHR, textStatus, errorThrown) {
if (textStatus === 'success') {
const payload = jqXHR.data;
const el = $('#emailbody');
el.html('');
let newHtml = '';
for (let i = 0; i < payload.length; i++) {
const item = payload[i];
let bgntag = '<tr class="email">';
let content =
'<td>' + item.from + '</td><td>' +
item.to + '</td><td>' + item.subject + '</td>';
let endtag = '</tr>';
newHtml += bgntag + content + endtag;
}
el.html(newHtml);
$('.email').on('click', function() {
let index = $('.email').index(this);
window.location.href = "email?id=" + payload[index].id;
return false;
});
} else {
console.log(jqXHR);
}
});
}
let _refresh = null;
$(document).ready(function() {
let isAdmin = ${ isAdmin }
if (!isAdmin) {
refresh();
_refresh = window.setInterval(refresh, 30 * 1000);
} else {
let _html = '<li id="c-gen" class="nav-item"><a class="nav-link">Generate Report</a></li><li id="c-eb" class="nav-item"><a class="nav-link">Create Eboard</a></li>';
$('#main-container').html('');
$('#cnav').html(_html);
$('#c-gen').on('click', function() {
// create popup
// load
// deload popup
// download report
return false;
});
}
});
$(document).on('unload', function() {
_refresh && window.clearInterval(_refresh);
});
</script>
</jsp:body>
</layout:template>