-1

小服务程序代码:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession();
    Facade f = new Facade();
    //f.hotspots() return a list of object used as marker***
    session.setAttribute("hotspots", f.hotspots());
    prossimaPagina = "/map.jsp";
    ServletContext application = getServletContext();
    RequestDispatcher rd = application.getRequestDispatcher(prossimaPagina);
    rd.forward(request, response);
    return;
}

java脚本代码:

<script type="text/javascript">
var map;
function initialize() {
  var myLatlng = new google.maps.LatLng(10,10);
  var mapOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
  placeMarker();
}

function placeMarker() {
    var icon = 'icon/hs.png';
    var hotspotList = <%=session.getAttribute("hotspots")%>;
    for ( var h in hotspotList ) {
    var marker = new google.maps.Marker({
        position: (h.getLat(),h.getLng()),
        map: map,
        icon: icon
    });
    }
}
    google.maps.event.addDomListener(window, 'load', initialize);
</script>

我知道这种<%=session.getAttribute("hotspots")%>表达方式是错误的,但我想做这样的事情。我怎样才能做到这一点?

4

1 回答 1

-2

像这样使用

首先在jsp中设置一个变量

<% 
    List<String> param= List<String>session.getAttribute("hotspots");
 %>

然后像这样使用。

 <script>
    var h = '<%=param%>';
 </script>
于 2013-05-20T15:30:30.767 回答