I'm trying to add a WFS layer in openlayers and it's not working. Can anyone point me in the right direction.

The data is stored in postgis and I've added it to geoserver. I am aware that I'm using port 8081 on geoserver but I can't forsee this being an issue. It would be useful to know where I'm going wrong.

Here is the code:

<!DOCTYPE html>
<script type="text/javascript" src="http://maps.nationalparks.gov.uk/resources/openlayers/OpenLayers.js"></script> 
<script type="text/javascript" src="http://maps.nationalparks.gov.uk/resources/js/geotools2.js"></script>
<script type="text/javascript"> 

var map;

function init() {
map = new OpenLayers.Map('map_element', {});

var wms = new OpenLayers.Layer.WMS(
'OpenLayers WMS',
{layers: 'basic'},

var world_cities = new OpenLayers.Layer.Vector("world_cities", {

                minScale: 15000000,
                strategies: [new OpenLayers.Strategy.BBOX()],
                protocol: new OpenLayers.Protocol.WFS({
                    url: "http://localhost:8081/geoserver/web",
                    featureType: "world_cities",
                    featureNS: "http://www.opengeospatial.net/cite"
                renderers: ['Canvas','SVG']




<body onload='init();'>
<div id='map_element' style='width: 500px; height: 500px; border-style:solid; border-width:5px;'>
  • do you see any error or response in firebug? Nov 25, 2012 at 11:05
  • I use Aptana (tried Firebug too) but couldn't see an error.
    – Matt T
    Nov 26, 2012 at 21:04

2 Answers 2


Do you run your application on same host and port with GeoServer (localhost:8081)? If not, same origin policy disallows web page to access WFS service. Install proxy and point OpenLayers.ProxyHost to it. For example: http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#WhydoIneedaProxyHost

  • I am running the application using apache and geoserver from my local machine. From what I can see this refers to accessing a wfs from a remote server. Thanks though as I wasn't aware of this before.
    – Matt T
    Nov 26, 2012 at 7:55

Are you sure that the WMS url is http://localhost:8081/geoserver/web ? It usually is something like this



  • Of course, thanks. Stupid mistake there but it still doesn't solve it.
    – Matt T
    Nov 26, 2012 at 7:52
  • @MattT do you see any error in firebug? Nov 26, 2012 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.