ArcIMS结合struts进行webGIS开发

本文介绍如何使用Struts框架封装ArcIMS的地图请求,实现业务逻辑与界面代码的分离,提高开发效率。通过具体示例展示了如何配置Struts Action及编写相关代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

arcIMS的客户端开发模式分HTML Viewer和Java Viewer两种,Java Viewer由于需要在客户端安装JRE,在webGIS开发中已经被一棒打死。而arcIMS提供的HTML Viewer中,大量处理地图的代码都是用JavaScript编写,界面代码和业务处理代码大量的混杂在一起,调试起来很不方便。利用struts对arcIMS请求代码进行封装,实现了业务代码和界面代码的分离。进行JSP开发时,利用可中MVC框架使得开发起来非常便利。比较有名的MVC框架有struts,spring等。简单,快捷的Struts是应用最广泛的一个。

(1)在struts中新建一个action
<action-mappings >
    <action
      attribute="requestMapForm"
      input="/index1.jsp"
      name="requestMapForm"
      path="/requestMap"
      scope="request"
      type="com.suzhou.struts.action.RequestMapAction" />
  </action-mappings>
(2)在map.jsp中新建一个form,对应这个action,记住,struts的<url-pattern>必须设置成*.do的格式(在web.xml中设置),如果设置成/do/*格式,多次请求这个action会出现找不到action的错误。

字串5


<FORM action="requestMap.do" name="requestMapForm">
<INPUT type="submit" value="确定"/>
</FORM>
(3)编写action代码

字串1

 

  代码 
   package  com.suzhou.struts.action;
   
   import  javax.servlet.http.HttpServletRequest;
   import  javax.servlet.http.HttpServletResponse; 字串6
   
   import  org.apache.struts.action.Action;
   import  org.apache.struts.action.ActionForm;
   import  org.apache.struts.action.ActionForward;
   import  org.apache.struts.action.ActionMapping;
  
字串7

  import  com.esri.aims.mtier.io.ConnectionProxy;
  import  com.esri.aims.mtier.model.map.Map;
  import  com.suzhou.struts.form.RequestMapForm;
  
  /** */ /**   字串8
  * MyEclipse Struts
  * Creation date: 03-29-2006
  * 
  * XDoclet definition:
  * @struts.action path="/requestMap" name="requestMapForm" input="jspForm.jsp" scope="request" validate="true"
  */ 
  public   class  RequestMapAction  extends  Action  {

字串6


  
  //  --------------------------------------------------------- Instance Variables
  
  //  --------------------------------------------------------- Methods 
  
  /** */ /**  
字串9

   * Method execute
   *  @param  mapping
    *  @param  form
    *  @param  request
    *  @param  response
    *  @return  ActionForward

字串4


      */ 
     public  ActionForward execute(
       ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
         HttpServletResponse response)   { 字串5
         RequestMapForm requestMapForm  =  (RequestMapForm) form;
        String strAction = requestMapForm.getAction();
        
        ConnectionProxy conn  =   new  ConnectionProxy();
        conn.setHost( " menglikun " ); // ArcIMS服务器的名称或者IP  字串1
        conn.setConnectionType(conn.TCP);
        conn.setPort( 5300 ); // ArcIMS服务器的端口 
        conn.setService( " zixian " ); // 需要调用的ArcIMS服务器的服务名称 
        conn.setDisplayMessages( false );
字串5

         // 使用Map对象的访问方式 
        /**/ /* 
         Map map=(Map)request.getSession().getAttribute("gongzhongMap");
         if(map==null){ 字串7
             //如果Map对象为空,新建一个Map对象
             map=new Map();
             try{
                 map.initMap(conn,0,false,false,false,false);
                 map.refresh();
                 request.setAttribute("mapURL",map.getMapOutput().getURL());
字串5

                 request.getSession().setAttribute("gongzhongMap",map);
                 return mapping.getInputForward();
             }catch(Exception ex){
                 System.out.println(ex.getMessage());
                 ex.printStackTrace(); 字串1
             }
         }else{
             map.refresh();
             request.setAttribute("mapURL",map.getMapOutput().getURL());
             request.getSession().setAttribute("gongzhongMap",map);
             return mapping.getInputForward();

字串6


         }
          */ 
         /**/ /* 
          * 不使用Map对象,直接通过arcXML进行请求的访问方式。
          * 这种方式的好处是可以使用arcXML所有的功能,功能非常强大。

字串7


          * 但要自己写代码处理arcIMS返回的结果。
           */ 
         String strArcXML = " <?xml version=/ " 1.0 / "  encoding=/ " UTF - 8 / "  ?> " 

字串7


              + " <ARCXML version=/ " 1.1 / " > " 
              + " <REQUEST> " 
              + " <GET_IMAGE> " 
字串9

              + " <PROPERTIES> " 
              + " <ENVELOPE minx=/ " - 13.62 / "  miny=/ " 33.91 / "  maxx=/ " 53.62 / "  maxy=/ " 73.33 / "  /> " 
字串8

              + " <IMAGESIZE width=/ " 600 / "  height=/ " 400 / " /> " 
              + " </PROPERTIES> " 

字串8


              + " <LAYER type=/ " acetate/ "  name=/ " acetate/ "  id=/ " acetate/ " > " 
              + " <OBJECT units=/ " pixel/ " > "  字串5
              + " <NORTHARROW type=/ " 4 / "  coords=/ " 20   30 / "  shadow=/ " 32 , 32 , 32 / "  size=/ " 15 / "  /> " 
字串9

              + " </OBJECT> " 
              + " </LAYER> " 
              + " </GET_IMAGE> "  字串8
              + " </REQUEST> " 
              + " </ARCXML> " ;
          try {

字串7


             conn.send(strArcXML);
             return  mapping.getInputForward();
        } catch (Exception ex)  {
             System.out.println(ex.getMessage()); 字串6
           ex.printStackTrace();
        }
102          return   null ;
103     }
104 }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冷月宫主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值