Posted on 2006-03-30 10:59
Kevin Meng 阅读(272)
评论(0) 编辑 收藏
进行JSP开发时,利用可中MVC框架使得开发起来非常便利。比较有名的MVC框架有struts,spring等。简单,快捷的Struts是应用最广泛的一个。
arcIMS的客户端开发模式分HTML Viewer和Java Viewer两种,Java Viewer由于需要在客户端安装JRE,在webGIS开发中已经被一棒打死。而arcIMS提供的HTML Viewer中,大量处理地图的代码都是用JavaScript编写,界面代码和业务处理代码大量的混杂在一起,调试起来很不方便。利用struts对arcIMS请求代码进行封装,实现了业务代码和界面代码的分离。
(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的错误。
<FORM action="requestMap.do" name="requestMapForm">
<INPUT type="submit" value="确定"/>
</FORM>
(3)编写action代码
代码
1
package
com.suzhou.struts.action;
2
3
import
javax.servlet.http.HttpServletRequest;
4
import
javax.servlet.http.HttpServletResponse;
5
6
import
org.apache.struts.action.Action;
7
import
org.apache.struts.action.ActionForm;
8
import
org.apache.struts.action.ActionForward;
9
import
org.apache.struts.action.ActionMapping;
10
11
import
com.esri.aims.mtier.io.ConnectionProxy;
12
import
com.esri.aims.mtier.model.map.Map;
13
import
com.suzhou.struts.form.RequestMapForm;
14
15
/** */
/**
16
* MyEclipse Struts
17
* Creation date: 03-29-2006
18
*
19
* XDoclet definition:
20
* @struts.action path="/requestMap" name="requestMapForm" input="jspForm.jsp" scope="request" validate="true"
21
*/
22
public
class
RequestMapAction
extends
Action
{
23
24
//
--------------------------------------------------------- Instance Variables
25
26
//
--------------------------------------------------------- Methods
27
28
/** */
/**
29
* Method execute
30
*
@param
mapping
31
*
@param
form
32
*
@param
request
33
*
@param
response
34
*
@return
ActionForward
35
*/
36
public
ActionForward execute(
37
ActionMapping mapping,
38
ActionForm form,
39
HttpServletRequest request,
40
HttpServletResponse response)
{
41
RequestMapForm requestMapForm
=
(RequestMapForm) form;
42
String strAction
=
requestMapForm.getAction();
43
44
ConnectionProxy conn
=
new
ConnectionProxy();
45
conn.setHost(
"
menglikun
"
);
//
ArcIMS服务器的名称或者IP
46
conn.setConnectionType(conn.TCP);
47
conn.setPort(
5300
);
//
ArcIMS服务器的端口
48
conn.setService(
"
zixian
"
);
//
需要调用的ArcIMS服务器的服务名称
49
conn.setDisplayMessages(
false
);
50
51
//
使用Map对象的访问方式
52
/**/
/*
53
Map map=(Map)request.getSession().getAttribute("gongzhongMap");
54
if(map==null){
55
//如果Map对象为空,新建一个Map对象
56
map=new Map();
57
try{
58
map.initMap(conn,0,false,false,false,false);
59
map.refresh();
60
request.setAttribute("mapURL",map.getMapOutput().getURL());
61
request.getSession().setAttribute("gongzhongMap",map);
62
return mapping.getInputForward();
63
}catch(Exception ex){
64
System.out.println(ex.getMessage());
65
ex.printStackTrace();
66
}
67
}else{
68
map.refresh();
69
request.setAttribute("mapURL",map.getMapOutput().getURL());
70
request.getSession().setAttribute("gongzhongMap",map);
71
return mapping.getInputForward();
72
}
73
*/
74
/**/
/*
75
* 不使用Map对象,直接通过arcXML进行请求的访问方式。
76
* 这种方式的好处是可以使用arcXML所有的功能,功能非常强大。
77
* 但要自己写代码处理arcIMS返回的结果。
78
*/
79
String strArcXML
=
"
<?xml version=\
"
1.0
\
"
encoding=\
"
UTF
-
8
\
"
?>
"
80
+
"
<ARCXML version=\
"
1.1
\
"
>
"
81
+
"
<REQUEST>
"
82
+
"
<GET_IMAGE>
"
83
+
"
<PROPERTIES>
"
84
+
"
<ENVELOPE minx=\
"
-
13.62
\
"
miny=\
"
33.91
\
"
maxx=\
"
53.62
\
"
maxy=\
"
73.33
\
"
/>
"
85
+
"
<IMAGESIZE width=\
"
600
\
"
height=\
"
400
\
"
/>
"
86
+
"
</PROPERTIES>
"
87
+
"
<LAYER type=\
"
acetate\
"
name=\
"
acetate\
"
id=\
"
acetate\
"
>
"
88
+
"
<OBJECT units=\
"
pixel\
"
>
"
89
+
"
<NORTHARROW type=\
"
4
\
"
coords=\
"
20
30
\
"
shadow=\
"
32
,
32
,
32
\
"
size=\
"
15
\
"
/>
"
90
+
"
</OBJECT>
"
91
+
"
</LAYER>
"
92
+
"
</GET_IMAGE>
"
93
+
"
</REQUEST>
"
94
+
"
</ARCXML>
"
;
95
try
{
96
conn.send(strArcXML);
97
return
mapping.getInputForward();
98
}
catch
(Exception ex)
{
99
System.out.println(ex.getMessage());
100
ex.printStackTrace();
101
}
102
return
null
;
103
}
104
}