Ciao a tutti! Ho esperienza con l'html e il css ma ho problemi a fare funzionare correttamente la jsp del sito che sto creando, probabilmente per un errore nel codice che ho scritto dentro questa pagina. Dovrebbe caricare una mappa di google con dei markers, le info dei quali si trovano su un database, ma non lo fa.
Quando faccio partire Tomcat e scrivo l'indirizzo del mio sito localhost:8080... carica la pagina code.html senza problemi:essa è poi legata alla pagina.js e alla .jsp.
main.js
codice:
function addMarker(posizione, titolo,contenuto){
var marker = new google.maps.Marker({
position: posizione,
map: map,
title:titolo });
var infowindow = new google.maps.InfoWindow({content: contenuto});
google.maps.event.addListener(marker, 'click', function() {infowindow.open(map, marker);});
return marker;
}
function geocode(indirizzo,desc,content){
geocoder.geocode( { 'address': indirizzo}, function(results, status) {
//alert(status+" -- "+google.maps.GeocoderStatus.OK);
if (status == google.maps.GeocoderStatus.OK) {
addMarker(results[0].geometry.location,desc,content);
}
}
);
}
var map;
var geocoder = new google.maps.Geocoder();
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(44.6885,10.6649),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
/*
ROADMAP displays the normal, default 2D tiles of Google Maps.
SATELLITE displays photographic tiles.
HYBRID displays a mix of photographic tiles and a tile layer for prominent features (roads, city names).
TERRAIN displays physical relief tiles for displaying elevation and water features (mountains, rivers, etc.).
*/
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
fx();
}
google.maps.event.addDomListener(window, 'load', initialize);
Non credo sia questa pagina a dare problemi perchè come 'prova del 9' ho messo nella jsp dentro i tag <% %> dei valori di prova riempendo un array con terne di valori (nome localita telefono) che passati alla jsp creavano dei Markers sulla mappa che stavano a indicare punti di interesse. E il tutto funzionava.
Non contento, ci chiede di abbandonare la soluzione con l'array allo scopo di scrivere una minore quantità di codice dentro i tag <% %> e creare con java un database da riempire con tutti i valori e una volta creato connettersi ad esso ed interrogarlo con una select.
Lo stesso identico discorso, però con un database. Ho creato il file.db non mi resta che collegarmi ad esso dentro la jsp ed è qui che trovo delle difficoltà e dove potrei aver fatto degli errori 
posto il codice della jsp:
codice:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0,
user-scalable=no" />
<style type="text/css">
#map-canvas { height: 300px;
width: 300px;
}
</style>
<script type="text/javascript" src="
https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript">
function fx() {
<%@ page language="java" import="java.sql.*" %>
<%
Class.forName("org.sqlite.JDBC");
Connection c = DriverManager.getConnection("jdbc:sqlite:db1.db");
Statement s = c.createStatement();
String nome=request.getParameter("nome");
String localita=request.getParameter("localita");
String telefono=request.getParameter("telefono");
String querySQL = "";
querySQL= "select * from db1";
ResultSet rs=s.executeQuery(querySQL);
while((rs.next())!=null){
System.out.println(rs.getString("nome"));
System.out.println(rs.getString("localita"));
System.out.println(res.getString("telefono"));
}
s.executeUpdate(querySQL);
rs.close();
s.close();
c.close();
%>
}
</script>
</head>
<body>
<h1 onclick="addP()">Example</h1>
<div id="map-canvas"/>
</body>
</html>
posto anche, per completezza il codice della pagina.html:
codice:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700|Archivo+Narrow:400,700" rel="stylesheet" type="text/css">
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div id="banner-wrapper"></div>
<div id="header-wrapper">
<div id="header" class="container">
<div id="logo">
<h1>MAPS</h1>
</div>
<div id="menu">
</div>
</div>
</div>
<div id="page" class="container">
<div id="content">
<div class="post">
<h2 class="title">Looking for...</h2>
<form action="ngeocoder.jsp">
<select name="localita">
<option value="restaurant">Restaurant</option>
<option value="disco">Disco</option>
<option value="pub">Pub</option>
<option value="fast food">Fast food</option>
<option value="shopping mall">Shopping Mall</option>
</select>
<input type="submit" value="Search!">
</form>
<div class="fb-like" data-href="http://localhost:8080/prova13/prova/code.html" data-send="true" data-width="450" data-show-faces="true"></div>
</div>
<div style="clear: both;"></div>
</div>
</div>
</html>
ma purtroppo
:
HTTP Status 404 - /tesina/mappa/ngeocoder.jsp
type Status report
message /tesina/mappa/ngeocoder.jsp
description The requested resource is not available.
Apache Tomcat/7.0.37
Ringrazio anticipatamente per l'attenzione.