最简单的mapxtreme的servlet例子
import java.io.*;
import javax.servlet.http.*;
import java.awt.Color;
import javax.servlet.*;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.mapxtreme.client.MapXtremeImageRenderer;
import com.mapinfo.util.*;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
public class SimpleServlet extends HttpServlet
{
//输出图片的格式
private static String mimeType = "image/gif";
//地图定义文件的位置
private static String m_mapPath = "D:\\MapXtreme8\\MapXtreme-4.8.2\\examples\\server\\data\\local\\world.mdf";
//mapxtremeservlet的url
private static String m_mxtURL = "http://localhost:8085/mapxtreme482/servlet/mapxtreme";;
//实现HttpServlet的doGet方法
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
//设置ContentType
response.setContentType(mimeType);
//返回响应的输出流
ServletOutputStream sos = response.getOutputStream();
//创建MapJ对象
MapJ m_mapj = new MapJ();
//加载地图
m_mapj.loadMapDefinition(m_mapPath);
//设置地图大小
m_mapj.setDeviceBounds(new DoubleRect(0,0,800,600));
try
{
//创建图像请求器(包装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("Error");
e.printStackTrace();
}
}
}