// 输出图片的格式
private static String mimeType = "image/gif";
// mapxtremeservlet地图服务器url
private static String m_mxtURL = "http://localhost:8080/mapxtreme482/servlet/mapxtreme";
// 实现HttpServlet的doGet方法
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
// 设置ContentType
response.setContentType(mimeType);
// 返回响应的输出流
ServletOutputStream sos = response.getOutputStream();
// 创建MapJ对象
MapJ m_mapj = new MapJ();
// 加载地图
System.out.println("111111");
String m_mapPath = "c:\\map\\dzmapall.gst";
String dataDir = "c:\\map";
System.out.println("222222");
try {
m_mapj.loadGeoset(m_mapPath, dataDir, m_mapPath);  // ×××××××报错
// 设置地图大小
System.out.println("2222");
m_mapj.setDeviceBounds(new DoubleRect(0, 0, 900, 900));
request.getSession().setAttribute("worldMap", m_mapj);
// 创建图像请求器(包装mapj对象,图片的色位,底色,格式信息)
ImageRequestComposer irc = ImageRequestComposer.create(m_mapj, 256,
Color.white, mimeType);
// 创建mxtj的图像渲染器
MapXtremeImageRenderer renderer = new MapXtremeImageRenderer(
m_mxtURL);
// 用渲染器渲染请求器
renderer.render(irc);
// 渲染器输出图片流到输出流,客户端显示之
renderer.toStream(sos);
// 释放渲染器对象
renderer.dispose();
} catch (Exception e) {
System.out.println();
e.printStackTrace();
}



} catch (Exception e) {
System.out.println("Error错误");
e.printStackTrace();
}
}//××××××××××××××××××××××××××
报错
111111  测试
222222测试
java.io.IOException: unknown protocol: c
at com.mapinfo.mapj.GeosetParser.parseGeoset(Unknown Source)
at com.mapinfo.mapj.GeosetParser.<init>(Unknown Source)
at com.mapinfo.mapj.GeosetParser.parseGeoset(Unknown Source)
at com.mapinfo.mapj.MapJ.loadGeoset(Unknown Source)
at com.mapinfo.mapj.MapJ.loadGeoset(Unknown Source)
at com.zh.testMapx.TestMapx.doGet(TestMapx.java:41)

解决方案 »

  1.   

    第三个参数给错了,应该是渲染器的url。
    mapxtreme java 分本地渲染和远程渲染,不过一般都是用远程渲染,这个就是那个渲染服务的url。看看例子怎么写的吧。
    public void loadGeoset(java.lang.String filename,
                           java.lang.String dataDir,
                           java.lang.String servletURL)
                    throws java.io.IOException    Read a Geoset from a file.    This function reads a Geoset and initializes this object from that data.    Parameters:
            filename - The directory path and filename of a Geoset file.
            dataDir - The directory where the TAB files are located on the server.
            servletURL - The URL of the MapXtremeServlet. This should be specified when one wants the Layers referenced by the geoset to use a MapXtremeDataProviderRef. When this is null, the Layers will use a LocalDataProviderRef.
        Throws:
            java.io.IOException - The implementation of this method can throw an arbitrary exception. The caller is responsible for catching and handling the exception.
        See Also:
            com.mapinfo.mapj.MapJ.loadGeoset(InputStream in, String dataDir, String servletURL)
      

  2.   

    // mapxtremeservlet地图服务器url
    private static String m_mxtURL = "http://localhost:8080/mapxtreme482/servlet/mapxtreme";
    // 实现HttpServlet的doGet方法
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    没有错啊,这样不对吗??