Java 加载页面时未加载值
我正在编写一个web应用程序,当index.jsp打开时,必须从数据库中提取一些值并显示为标题。在我当前的场景中,当我从eclipse运行项目时,它会显示值,而当我试图通过将项目导出到war并从tomcat单独部署它来执行相同的操作时,它不会工作。下面是文件 Index.jspJava 加载页面时未加载值,java,eclipse,jsp,tomcat,Java,Eclipse,Jsp,Tomcat,我正在编写一个web应用程序,当index.jsp打开时,必须从数据库中提取一些值并显示为标题。在我当前的场景中,当我从eclipse运行项目时,它会显示值,而当我试图通过将项目导出到war并从tomcat单独部署它来执行相同的操作时,它不会工作。下面是文件 Index.jsp <%@page import="org.bean.UserBean"%> <%@ page language="java" contentType="text/html; charset=ISO-885
<%@page import="org.bean.UserBean"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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=ISO-8859-1">
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="myCssFile.css">
<title>Insert title here</title>
<script type="text/javascript">
function enableSubmit() {
document.getElementById("getCase").disabled = true;
document.getElementById("submitButton").disabled = false;
}
function enableGetCase() {
document.getElementById("getCase").disabled = false;
document.getElementById("submitButton").disabled = true;
}
</script>
</head>
<body>
<div class="header" id="header">
<form id="form1"></form>
</div>
<div class="bodytag">
<form method="get" action="GetData">
<input type="Submit" value="Get Case" name="getCase" id="getCase"
onclick="enableSubmit()" />
<table>
<tr>
<td>Case Number</td>
<td><input id="Text1" type="text" value="" /></td>
<td>Case Owner</td>
<td><input id="Text6" type="text" value="" /></td>
</tr>
<tr>
<td>Source</td>
<td><input id="Text2" type="text" /></td>
<td>Status</td>
<td><input id="Text7" /></td>
</tr>
<tr>
<td class="auto-style2">Issue</td>
<td class="auto-style2"><input id="Text3" value="" type="text" /></td>
<td class="auto-style2">Reason</td>
<td class="auto-style2"><input id="Text8" value="" type="text" /></td>
</tr>
<tr>
<td>Date/Time Opened</td>
<td><input id="Text4" type="text" value="" /></td>
<td>Age(Days)</td>
<td><input id="Text10" type="text" value="" /></td>
</tr>
<tr>
<td>Resolution</td>
<td><select id="Select1" name="D1">
<option></option>
</select></td>
<td>Final Status</td>
<td><select id="Select2" name="D2">
<option value=" "></option>
</select></td>
</tr>
<tr>
<td>Start Time</td>
<td><input id="Text5" type="text" value="Start Time" /></td>
<td>End Time</td>
<td><input id="Text9" type="text" value="end Time" /></td>
</tr>
</table>
<input type="button" value="Submit" name="submitButton"
id="submitButton" disabled="disabled" onClick="enableGetCase()" />
</form>
</div>
<script type="text/javascript" src="SampleJS.js"></script>
</body>
获取countsdao
package org.DAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.code.general.DBConnection;
public class GetTheCountsDAO {
DBConnection dbConnection = new DBConnection();
int excelCount, DBCount, effeciency;
double timeTaken = -1.0;
public int getTotalFromExcel() throws Exception {
Connection conn = dbConnection.getConn();
Statement stmt = dbConnection.getStmt();
ResultSet rs = dbConnection.getRs();
String excelPath = dbConnection.getExcelPath();
String queryString = null;
dbConnection.createClassForNameForExcel();
conn = DriverManager.getConnection(
"jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + excelPath + "; READONLY=FALSE;");
stmt = conn.createStatement();
queryString = "SELECT COUNT(*) as CNT from [report1448039568905$]";
rs = stmt.executeQuery(queryString);
rs.next();
excelCount = rs.getInt("CNT");
rs.close();
return excelCount;
}
public int getTotalFromDB() throws Exception {
Connection conn = dbConnection.getConn();
Statement stmt, stmt1 = dbConnection.getStmt();
ResultSet rs, rs1 = dbConnection.getRs();
String queryString, queryString1 = null;
dbConnection.createClassForNameForSQLServer();
String userName = "sa";
String password = "T!ger123";
String url = "jdbc:sqlserver://U0138039-TPD-A\\SQLEXPRESS;DatabaseName=TEST";
dbConnection.createClassForNameForSQLServer();
conn = DriverManager.getConnection(url, userName, password);
stmt = conn.createStatement();
queryString = "SELECT COUNT(*) as CNT from statusTable";
rs = stmt.executeQuery(queryString);
rs.next();
DBCount = rs.getInt("CNT");
rs.close();
stmt.close();
stmt1 = conn.createStatement();
queryString1 = "select sum([Time Taken(minutes)]) as timeTaken from statusTable";
rs1 = stmt1.executeQuery(queryString1);
rs1.next();
timeTaken = rs1.getDouble(1);
stmt1.close();
conn.close();
return DBCount;
}
public double getEffeciency() throws Exception {
double getAtcualProcessed = DBCount / timeTaken;
double effeciency = (getAtcualProcessed / 8) * 100;
return Math.round(effeciency * 100) / 100.00;
}
}
SampleJS.js
$(window).load(
function() {
$("#form1").on(
'submit',
function(e) {
$.ajax({
type : "get",
url : "GetTheCounts",
data : $(this).serialize(),
success : function(msg) {
console.log(JSON.stringify(msg));
var $span = $('<span class="totalTime">')
.appendTo($('#header'));
$span.append("Status: (Worked/Total) -")
.append("\t\t\t\t\t").append(
msg.DAOCount).append("/")
.append(msg.excelCount);
var $span1 = $('<span class="effeciency">')
.appendTo($('#header'));
$span1.append("Effeciency : ").append(
msg.effeciency);
}
});
e.preventDefault();
}).submit();
});
请告诉我哪里出了问题。我怎样才能解决这个问题。这在Eclipse浏览器中可以正常工作,但在外部浏览器中不行
以下是我的产出
在Eclipse中部署
在Tomcat web GUI中外部部署为WAR
在Eclipse中,我使用Tomcat 8.0,在外部使用7.0,在导出到WAR时,我已取消选中服务器兼容性复选框
在Eclipse中,端口是8080,对于外部Tomcat,我使用了9090(只是为了确保没有混淆)。您可以在开发人员控制台中检查tat SampleJs.js文件是否由浏览器加载吗?Hi@Lathy,这很有帮助,缺少一些JSON库。再次感谢您的意思是缺少js文件?@Lathy,所有支持JSON的文件。请您在开发人员控制台中检查tat SampleJs.js文件是否由浏览器加载?您好@Lathy,这很有用,缺少一些JSON库。再次感谢你是说js文件丢失了?@Lathy,所有支持JSON的文件。
$(window).load(
function() {
$("#form1").on(
'submit',
function(e) {
$.ajax({
type : "get",
url : "GetTheCounts",
data : $(this).serialize(),
success : function(msg) {
console.log(JSON.stringify(msg));
var $span = $('<span class="totalTime">')
.appendTo($('#header'));
$span.append("Status: (Worked/Total) -")
.append("\t\t\t\t\t").append(
msg.DAOCount).append("/")
.append(msg.excelCount);
var $span1 = $('<span class="effeciency">')
.appendTo($('#header'));
$span1.append("Effeciency : ").append(
msg.effeciency);
}
});
e.preventDefault();
}).submit();
});
@CHARSET "ISO-8859-1";
.header {
position: fixed;
top: 1em;
left: 0px;
width: 100%;
padding-bottom: 3em;
border-bottom: 1px solid black;
background: #ff8800;
}
.bodytag {
margin-top: 7em;
display: table;
margin-right: auto;
margin-left: auto;
border: 1px solid lightgray;
padding: 3em;
}
span.totalTime {
display: block;
float: left;
margin-left: 1.5em;
position: absolute;
top: 30px;
color: white;
font-weight: bold;
}
span.effeciency {
display: block;
float: right;
width: auto;
margin-right: 2em;
top: 30px;
position: relative;
color: white;
font-weight: bold;
}
#getCase {
margin-left: auto;
margin-right: auto;
margin-bottom: 1em;
display: block;
}
#submitButton {
margin-left: auto;
margin-right: auto;
margin-top: 1em;
display: block;
}
#postData {
margin-left: auto;
margin-right: auto;
margin-top: 1em;
display: block;
}
table {
border-spacing: 10px;
border-collapse: separate;
}