在我的项目中,JSP页面加载时间太长。我在jsp页面中有很多javascript代码和 AJAX 调用。我的一个jsp页面代码如下
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*"%>
<%@page import="org.solr.dbJava"%>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.Date" %>
<%@page import="org.solr.SolrJava" %>
<%@page import="org.apache.solr.common.SolrDocumentList"%>
<%@page import="org.solr.userSolrJava" %>
<!DOCTYPE html>
<html>
<head>
<title>TEC E-Archive</title>
<link rel="stylesheet" href="css//jquery.dataTables.min.css">
<link rel="stylesheet" href="css//bootstrap.css">
<link rel="stylesheet" href="css//jquery-ui.css">
<link rel="icon" type="image" href="images//TEC.jpg">
<style>
{box-sizing: border-box;}
/* Button used to open the contact form - fixed at the bottom of the page */
.open-button {
background-color: #555;
color: white;
padding: 16px 20px;
border: none;
cursor: pointer;
opacity: 0.8;
position: fixed;
bottom: 100px;
right: 10%;
width: 55%;
}
/* The popup form - hidden by default */
.form-popup {
display: none;
position: fixed;
bottom: 100px;
right: 10%;
border: 3px solid #f1f1f1;
z-index: 9;
width:55%;
}
/* Add styles to the form container */
.form-container {
max-width: 100%;
padding: 10px;
background-color: white;
}
/* When the inputs get focus, do something */
.form-container input[type=text]:focus, .form-container input[type=password]:focus {
background-color: #ddd;
outline: none;
}
/* Set a style for the submit/login button */
.form-container .btn {
background-color: #4CAF50;
color: white;
padding: 16px 20px;
border: none;
cursor: pointer;
width: 100%;
margin-bottom:10px;
opacity: 0.8;
}
/* Add a red background color to the cancel button */
.form-container .cancel {
background-color: red;
}
/* Add some hover effects to buttons */
.form-container .btn:hover, .open-button:hover {
opacity: 1;
}
</style>
<script src="js//jquery-1.12.4.js"></script>
<script src="js//bootstrap.min.js"></script>
<script src="js//jquery.dataTables.min.js"></script>
<script src="js//jquery-ui.js"></script>
<% Class.forName("oracle.jdbc.driver.OracleDriver");Connection connect=DriverManager.getConnection("jdbc:oracle:thin:@172.18.132.29:1521:xe","SYSTEM","orc2002admin#");Statement state=connect.createStatement();%>
<script>
function salesOrder(){
var salesOrder=$("#sOrder option:selected").val();
$.ajax({
type:'get',
url:'getValues',
data:'salesOrder='+salesOrder,
dataType:'json',
success:function(data){
console.log("success");
var results=JSON.stringify(data);
document.getElementById("induction").value=data[0];
document.getElementById("customer").value=data[1];
document.getElementById("operator").value=data[2];
document.getElementById("rem_reason").value=data[3];
document.getElementById("tsn").value=data[4];
document.getElementById("csn").value=data[5];
document.getElementById("tslsv").value=data[6];
document.getElementById("cslsv").value=data[7];
}
});
};
</script>
<script>
if($.fn.dataTable.isDataTable( '#example_table' )){
var table = $('#example_table').DataTable();
}
$(document).ready(function fill_table(){
$('#example_table tbody').html('');
var URL="http://localhost:8983/solr/StorageCore/select?q=*%3A*&rows=9999&sort=idCopy%20desc&start=0&wt=json";
$.ajax({
url:URL,
dataType:'json',
jsonp : 'json.wrf',
type :'get',
cache :false,
success: function(data){
var docs=data.response.docs;
var html='';
$.each(docs,function(key,value){
html+='<tr>';
html+='<td>'+value.ID+'</td>';
html+='<td>'+value.strSO+'</td>';
if(value.strLocation==undefined)
html+='<td></td>';
else
html+='<td>'+value.strLocation+'</td>';
html+='<td>'+value.strBox+'</td>';
html+='<td>'+value.strFolder+'</td>';
if(value.strCustomer==undefined)
html+='<td></td>';
else
html+='<td>'+value.strCustomer+'</td>';
if(value.strOperator==undefined)
html+='<td></td>';
else
html+='<td>'+value.strOperator+'</td>';
html+='<td>'+value.strDate+'</td>';
if(value.strElectronicStoredDate==undefined)
html+='<td></td>';
else
html+='<td>'+value.strElectronicStoredDate+'</td>';
if(value.strStoredDate==undefined)
html+='<td></td>';
else
html+='<td>'+value.strStoredDate+'</td>';
if(value.strShippedDate==undefined)
html+='<td></td>';
else
html+='<td>'+value.strShippedDate+'</td>';
if(value.strSubmitName==undefined)
html+='<td></td>';
else
html+='<td>'+value.strSubmitName+'</td>';
if(value.strSubmitDate==undefined)
html+='<td></td>';
else
html+='<td>'+value.strSubmitDate+'</td>';
if(value.ExpiryDate==undefined)
html+='<td></td>';
else
html+='<td>'+value.ExpiryDate+'</td>';
if(value.Destructed==undefined)
html+='<td></td>';
else
html+='<td>'+value.Destructed+'</td>';
html+='</tr>';
});
$('#example_table').DataTable().destroy();
$('#example_table tbody').html(html);
var table=$('#example_table').DataTable({
"paging":true,
"searching":false,
"scrollY":"500px",
"scroller":true,
"pageLength":250,
"lengthChange": false,
"order": [[ 0, "desc" ]],
"colReorder": true,
"sScrollX": "100%",
"sScrollXInner": "400%",
"bScrollCollapse": true,
});
},
});
})
</script>
<script>
function openForm(){
document.getElementById("myForm").style.display = "block";
var salesOrder="\""+$("#sOrder option:selected").val()+"\"";
document.getElementById("sOrder_popup").value=$("#sOrder option:selected").val();
var URL_PREFIX="http://localhost:8983/solr/StorageCore/select?q=strSO:"
var URL_MIDDLE="&rows=99999&start=0&wt=json"
var URL=URL_PREFIX+salesOrder+URL_MIDDLE;
$.ajax({
url : URL,
dataType : 'json',
type:'get',
json : 'json.wrf',
cache :false,
success : function(data) {
var docs = JSON.stringify(data.response.docs);
var jsonData=JSON.parse(docs);
if(jsonData[0]===undefined||jsonData[0].strLocation===undefined)
document.getElementById("location_popup").value="";
else
document.getElementById("location_popup").value=jsonData[0].strLocation[0];
if(jsonData[0]===undefined||jsonData[0].strSubmitName===undefined)
document.getElementById("submitted_popup").value="";
else
document.getElementById("submitted_popup").value=jsonData[0].strSubmitName[0];
if(jsonData[0]===undefined||jsonData[0].strSubmitDate===undefined)
document.getElementById("subDate_popup").value="";
else
document.getElementById("subDate_popup").value=jsonData[0].strSubmitDate[0];
if(jsonData[0]===undefined||jsonData[0].strBox===undefined)
document.getElementById("boxCount").selectedIndex=0;
else
setBoxOption(jsonData[0].strBox);
if(jsonData[0]===undefined||jsonData[0].strEditName===undefined)
document.getElementById("editedBy").value="";
else
document.getElementById("editedBy").value=jsonData[0].strEditName[0];
if(jsonData[0]===undefined||jsonData[0].strFolder===undefined)
document.getElementById("folderCount").selectedIndex=0;
else
setFolderOption(jsonData[0].strFolder);
if(jsonData[0]===undefined||jsonData[0].strEditDate===undefined)
document.getElementById("editDate").value="";
else
document.getElementById("editDate").value=jsonData[0].strEditDate[0];
if(jsonData[0]===undefined||jsonData[0].strDate===undefined)
document.getElementById("releaseDate").value="";
else
document.getElementById("releaseDate").value=jsonData[0].strDate[0];
if(jsonData[0]===undefined||jsonData[0].ExpiryDate===undefined)
document.getElementById("expiryDate").value="";
else
document.getElementById("expiryDate").value=jsonData[0].ExpiryDate[0];
if(jsonData[0]===undefined||jsonData[0].strStoredDate===undefined)
document.getElementById("hardCopy").value="";
else
document.getElementById("hardCopy").value=jsonData[0].strStoredDate[0];
if(jsonData[0]===undefined||jsonData[0].Destructed===undefined)
document.getElementById("destructed").selectedIndex=0;
else
setDestOption(jsonData[0].Destructed[0]);
if(jsonData[0]===undefined||jsonData[0].strElectronicStoredDate===undefined)
document.getElementById("electronic").value="";
else
document.getElementById("electronic").value=jsonData[0].strElectronicStoredDate[0];
if(jsonData[0]===undefined||jsonData[0].strShippedDate===undefined)
document.getElementById("outSource").value="";
else
document.getElementById("outSource").value=jsonData[0].strShippedDate[0];
},
});
}
function closeForm(){
document.getElementById("myForm").style.display = "none";
location.reload();
}
function setBoxOption(optValue){
if(optValue==0)
document.getElementById("boxCount").selectedIndex=0;
else if(optValue==1)
document.getElementById("boxCount").selectedIndex=1;
else if(optValue==2)
document.getElementById("boxCount").selectedIndex=2;
else if(optValue==3)
document.getElementById("boxCount").selectedIndex=3;
else if(optValue==4)
document.getElementById("boxCount").selectedIndex=4;
else if(optValue==5)
document.getElementById("boxCount").selectedIndex=5;
else if(optValue==6)
document.getElementById("boxCount").selectedIndex=6;
else if(optValue==7)
document.getElementById("boxCount").selectedIndex=7;
else if(optValue==8)
document.getElementById("boxCount").selectedIndex=8;
else if(optValue==9)
document.getElementById("boxCount").selectedIndex=9;
else if(optValue==10)
document.getElementById("boxCount").selectedIndex=10;
}
function setFolderOption(optFolderValue){
if(optFolderValue==0)
document.getElementById("folderCount").selectedIndex=0;
else if(optFolderValue==1)
document.getElementById("folderCount").selectedIndex=1;
else if(optFolderValue==2)
document.getElementById("folderCount").selectedIndex=2;
else if(optFolderValue==3)
document.getElementById("folderCount").selectedIndex=3;
else if(optFolderValue==4)
document.getElementById("folderCount").selectedIndex=4;
else if(optFolderValue==5)
document.getElementById("folderCount").selectedIndex=5;
else if(optFolderValue==6)
document.getElementById("folderCount").selectedIndex=6;
else if(optFolderValue==7)
document.getElementById("folderCount").selectedIndex=7;
else if(optFolderValue==8)
document.getElementById("folderCount").selectedIndex=8;
else if(optFolderValue==9)
document.getElementById("folderCount").selectedIndex=9;
else if(optFolderValue==10)
document.getElementById("folderCount").selectedIndex=10;
}
function setDestOption(optValue){
if(optValue=="YES")
document.getElementById("destructed").selectedIndex=1;
else if(optValue=="NO")
document.getElementById("destructed").selectedIndex=2;
}
</script>
<script>
function addSO(){
var salesOrder=$("#sOrder_popup").val();
var location=$("#location_popup").val();
var box=$("#boxCount option:selected").val();
var folder=$("#folderCount option:selected").val();
var customer=$("#customer").val();
var operator=$("#operator").val();
var releaseDate=$("#releaseDate").val();
var electronic=$("#electronic").val();
var hardCopy=$("#hardCopy").val();
var shipped=$("#outSource").val();
var submitName=$("#submitted_popup").val();
var submitDate=$("#subDate_popup").val();
var expiryDate=$("#expiryDate").val();
var destructed=$("#destructed").val();
var editName=$("#editedBy").val();
var editDate=$("#editDate").val();
$.ajax({
type:'post',
url:'addStorage',
data:'salesOrder='+salesOrder+'&location='+location+'&box='+box+'&folder='+folder+'&customer='+customer+'&operator='+operator+'&releaseDate='+releaseDate+'&electronic='+electronic+'&hardCopy='+hardCopy+'&shipped='+shipped+'&submitName='+submitName+'&submitDate='+submitDate+'&expiryDate='+expiryDate+'&destructed='+destructed+'&editName='+editName+'&editDate='+editDate,
dataType:'text/plain',
success:function(data){
console.log("success");
document.getElementById("result").innerHTML='Adding SalesOrder is successfull.';
}
});
};
</script>
<script>
function editSO(){
var salesOrder=$("#sOrder_popup").val();
var location=$("#location_popup").val();
var box=$("#boxCount option:selected").val();
var folder=$("#folderCount option:selected").val();
var customer=$("#customer").val();
var operator=$("#operator").val();
var releaseDate=$("#releaseDate").val();
var electronic=$("#electronic").val();
var hardCopy=$("#hardCopy").val();
var shipped=$("#outSource").val();
var submitName=$("#submitted_popup").val();
var submitDate=$("#subDate_popup").val();
var expiryDate=$("#expiryDate").val();
var destructed=$("#destructed").val();
var editName=$("#editedBy").val();
var editDate=$("#editDate").val();
$.ajax({
type:'post',
url:'updateStorage',
data:'salesOrder='+salesOrder+'&location='+location+'&box='+box+'&folder='+folder+'&customer='+customer+'&operator='+operator+'&releaseDate='+releaseDate+'&electronic='+electronic+'&hardCopy='+hardCopy+'&shipped='+shipped+'&submitName='+submitName+'&submitDate='+submitDate+'&expiryDate='+expiryDate+'&destructed='+destructed+'&editName='+editName+'&editDate='+editDate,
dataType:'text',
success:function(data){
console.log("success");
document.getElementById("result").innerHTML='Editing SalesOrder is successfull.';
}
});
};
</script>
</head>
<body>
<div style="padding-left: 5%; padding-right: 5%; padding-top: 25px">
<div id="wrapper" style="width: 100%; text-align: left">
<img border="0" src="images//TEC.jpg" alt="TEC" width="170"
height="75">
<font size="6"> Electronic Archiving</font>
<%
String USERNAME=null;
String fullname=null;
Cookie[] cookies=request.getCookies();
if(cookies!=null){
for(Cookie cookie:cookies){
if(cookie.getName().equals("USERNAME"))USERNAME=cookie.getValue();
}
}
if(USERNAME==null) response.sendRedirect("Login.jsp");
ArrayList<String> strSO=new ArrayList<String>();
ResultSet rs1=state.executeQuery("SELECT * FROM USERT WHERE USERNAME='"+USERNAME+"'");
while(rs1.next())
fullname=rs1.getString("NAME")+" "+rs1.getString("LASTNAME");
%>
</div>
<div style="margin-left:75%;">
<label>Welcome <b><%=fullname %></b>, Login successful.</label></div><div style="margin-left:74%;"><form action="returnToFirstPageServlet" method="post"><button class="btn btn-sm">Return to First Page</button></form></div>
<div style="margin-left: 85%; margin-top:-30px;"><form action="LogoutServlet" method="POST"><input type="submit" value="Logout" class="btn btn-sm"></form></div>
<br>
<div style="margin-left:7%; margin-right:10%; border-style:groove;">
<div style="margin-right:65&; margin-left:5px; margin-top:10px;" >
<label for="salesOrder">Sales Order</label> <select id="sOrder" style="margin-left:58px; margin-top:3px;" onchange="salesOrder()"><% ResultSet rs=state.executeQuery("SELECT * FROM SalesOrder WHERE strSO LIKE 'E%' OR strSO LIKE 'R%'"); while(rs.next()){ %><option><%=rs.getString("strSO") %></option><%} %></select>  <br>
<label>Ind. Date:</label>  <input type="text" id="induction" style="margin-left:59px;" size="15"><br>
<label>Customer:</label> <textarea id="customer" rows="1" cols="10" wrap="soft" style="margin-left:70px;"></textarea> <label>Operator:</label> <textarea id="operator" rows="1" cols="10" wrap="soft"></textarea><br>
<label>Removal Reason:</label> <textarea rows="2" cols="30" wrap="soft" id="rem_reason" style="margin-left:10px; height:50px; text-size:10px;"></textarea>
</div>
<div style="margin-left:40%; margin-top:-70px;">
<input type="submit" value="Add / Edit / Show Sales-Order" onclick="openForm()" style="height:70px;white-space:normal;width:150px; margin-left:15%;">
</div>
<div style="margin-left:70%; margin-top:-130px;">
<label>TSN:</label>  <input type="text" id="tsn" style="margin-left:1px;"><br>
<label>CSN:</label>  <input type="text" id="csn" style="margin-left:-0.5px;"><br>
<label>TSLSV:</label>  <input type="text" id="tslsv" style="margin-left:-1px;"><br>
<label>CSLSV:</label>  <input type="text" id="cslsv" style="margin-left:-3px;">
</div>
</div>
<div class="form-popup" id="myForm">
<form class="form-container">
<h3>Add or Edit Archived Sales-Order</h3><br>
<label>Sales-Order:</label> <input type="text" id="sOrder_popup" size="10" style="margin-left:84px;" readonly>  <label>Submitted By:</label> <input type="text" id="submitted_popup" value="<%=fullname %>" size="20" readonly><br>
<label>Location:</label> <input type="text" id="location_popup" size="10" style="margin-left:107px;">  <label>Submit Date:</label> <input type="text" id="subDate_popup" size="20" style="margin-left:6.5px;" value="<%Date date=new Date(); %>" readonly><br>
<label>Box Count:</label> <select id="boxCount" style="margin-left:94px;"><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select>  <label style="margin-left:82px;">Edited By: </label><input type="text" id="editedBy" style="margin-left:44.5px;" value="<%=fullname %>" readonly><br>
<label>Folder Count:</label> <select id="folderCount" style="margin-left:76px;"><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select>  <label style="margin-left:81px;">Edit Date: </label><input type="text" id="editDate" style="margin-left:46.25px;" value="<%Date editDate=new Date(); %>" readonly><br>
<label>Engine Release Date:</label> <input type="text" id="releaseDate" style="margin-left:23px;" size="10">  <label style="margin-left:7px;">Doc. Expiry Date:</label> <input type="text" id="expiryDate" size="10"><br>
<label>HardCopy Storage Date:</label> <input type="text" id="hardCopy" style="margin-left:-2px;" size="10">  <label style="margin-left:7px;">Destructed:</label> <select id="destructed" style="margin-left:38.5px;"><option>-</option><option>YES</option><option>NO</option></select><br>
<label>Electronic Storage Date:</label> <input type="text" id="electronic" size="10">  <label style="margin-left:7px;">OutSource Shipping Date:</label> <input type="text" id="outSource" size="10"><br>
<button type="button" onclick="addSO()">Add Sales-Order</button>  <button type="button" onclick="editSO()">Edit Sales-Order</button>  <button type="button" onclick="closeForm()">Exit</button>  <b><label id="result" style="color:red;"></label></b>
</form>
</div>
<div style="margin-left:7%;margin-right:10%;">
<table id="example_table" class="table table-primary table-bordered table-sm table-hover">
<thead>
<tr style="font-size:11px;">
<th class="text-center" style="width:3%;">ID</th>
<th class="text-center" style="width:7%;">Sales-Order</th>
<th class="text-center" style="width:6%;">Location</th>
<th class="text-center" style="width:3%;">Box</th>
<th class="text-center" style="width:3%;">Folder</th>
<th class="text-center" style="width:6%;">Customer</th>
<th class="text-center" style="width:6%;">Operator</th>
<th class="text-center" style="width:6%;">Release Date</th>
<th class="text-center" style="width:6%;">Electronic Storage</th>
<th class="text-center" style="width:6%;">Hard Storage<br>---------------<br>Internal Storage</th>
<th class="text-center" style="width:6%;">Shipping Date<br>---------------<br>Outsourced Storage</th>
<th class="text-center" style="width:6%;">Submit Name</th>
<th class="text-center" style="width:6%;">Submit Date</th>
<th class="text-center" style="width:6%;">Expiry Date<br>---------------<br>Internal Storage</th>
<th class="text-center" style="width:3%;">Destructed?</th>
</tr>
</thead>
<tbody style="font-size:11px;"></tbody>
<tfoot>
<tr style="font-size:11px;">
<th class="text-center">ID</th>
<th class="text-center">Sales-Order</th>
<th class="text-center">Location</th>
<th class="text-center">Box</th>
<th class="text-center">Folder</th>
<th class="text-center">Customer</th>
<th class="text-center">Operator</th>
<th class="text-center">Release Date</th>
<th class="text-center">Electronic Storage</th>
<th class="text-center">Hard Storage<br>---------------<br>Internal Storage</th>
<th class="text-center">Shipping Date<br>---------------<br>Outsourced Storage</th>
<th class="text-center">Submit Name</th>
<th class="text-center">Submit Date</th>
<th class="text-center">Expiry Date<br>---------------<br>Internal Storage</th>
<th class="text-center">Destructed?</th>
</tr>
</tfoot>
</table>
</div>
</div>
</body>
</html>
我不明白为什么要花这么长的时间。jsp页面的加载时间如图所示
加载storage.jsp的文档类型需要362,28秒,太长了。有人对此问题有什么建议吗?
1条答案
按热度按时间c2e8gylq1#
我建议你检查你的数据库连接或其他资源,你正在进行连接,这是不可用的不幸。这将导致无限加载行为。
此外,实现超时会话并中断连接以防止更多的cpu/内存使用。