我想在AWS Elastic Beanstalk环境中发布我的Dynamic Web Project。我做了很多尝试和错误,发现我的问题的原因是下面的Scriptlet。一旦我删除它,我的网站工作。 (也许很有趣:我可以在没有问题的情况下使用scriptlet在tomcat localhost服务器上发布我的项目。
Scriptlet中:
<%
Twitter_String TS = new Twitter_String();
String TwitterString = TS.Twitter_Stringbuilder();
%>
var heatmapdata = [<%=TwitterString%>];
我真的查了所有内容,但无法找出为什么scriptlet不能在beanstalk环境中运行,而是在tomcat localhost服务器上运行。 My Beanstalk环境运行“运行Tomcat 7 Java 7的64位Amazon Linux 2015.03 v2.0.0”。我的Tomcat localhost也是版本7.请帮帮我。
我无法发布我的项目结构图片。但这是我的代码。我还在WEB-INF lib文件夹中包含了所有必需的.jars。
的index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="AP.Twitter.Twitter_String"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Heatmaps</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
#panel {
background-color: #fff;
border: 1px solid #999;
left: 25%;
padding: 5px;
position: absolute;
top: 10px;
z-index: 5;
}
</style>
</head>
<body>
<div id="panel">
<button onclick="toggleHeatmap()">Toggle Heatmap</button>
<button onclick="changeGradient()">Change gradient</button>
<button onclick="changeRadius()">Change radius</button>
<button onclick="changeOpacity()">Change opacity</button>
</div>
<div id="map"></div>
<script>
var map, heatmap;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: {lat: 37.775, lng: -122.434},
mapTypeId: google.maps.MapTypeId.SATELLITE
});
<%
Twitter_String TS = new Twitter_String();
String TwitterString = TS.Twitter_Stringbuilder();
%>
var heatmapdata = [<%=TwitterString%>];
heatmap = new google.maps.visualization.HeatmapLayer({
data: heatmapdata,
map: map
});
}
function toggleHeatmap() {
heatmap.setMap(heatmap.getMap() ? null : map);
}
function changeGradient() {
var gradient = [
'rgba(0, 255, 255, 0)',
'rgba(0, 255, 255, 1)',
'rgba(0, 191, 255, 1)',
'rgba(0, 127, 255, 1)',
'rgba(0, 63, 255, 1)',
'rgba(0, 0, 255, 1)',
'rgba(0, 0, 223, 1)',
'rgba(0, 0, 191, 1)',
'rgba(0, 0, 159, 1)',
'rgba(0, 0, 127, 1)',
'rgba(63, 0, 91, 1)',
'rgba(127, 0, 63, 1)',
'rgba(191, 0, 31, 1)',
'rgba(255, 0, 0, 1)'
];
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}
function changeRadius() {
heatmap.set('radius', heatmap.get('radius') ? null : 50);
}
function changeOpacity() {
heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?signed_in=true&libraries=visualization&callback=initMap">
</script>
</body>
</html>
DataBaseConnect,JAVA
package AP.Twitter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public abstract class DataBaseConnect {
protected static Connection getConnection() throws SQLException {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
};
return DriverManager.getConnection("jdbc:postgresql://*****",
"postgres", "*****");
}
}
Twitter_String.java
package AP.Twitter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Twitter_String extends DataBaseConnect{
public String Twitter_Stringbuilder() throws SQLException{
String query = new StringBuilder().append("SELECT * from tswholeworld").toString();
Connection con = getConnection();
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
StringBuilder stringBuilder = new StringBuilder();
String finalString;
try {
while(rs.next()) {
String lat = rs.getString(3);
String lon = rs.getString(4);
stringBuilder.append("new google.maps.LatLng("+lat+", "+lon+"), ");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finalString = stringBuilder.toString();
return finalString;
}
}