Posted on 2006-02-16 15:07
Kevin Meng 阅读(428)
评论(0) 编辑 收藏
由于struts的Action 类也是扩展自servlet所以新建一个mapxtreme servlet类扩展自Action类,这样就可以利用Action类的很多功能了。下面是一个示例代码。
样例代码
1package com.lingtu.tsgis.struts.action;
2
3import javax.servlet.http.HttpServletRequest;
4import javax.servlet.http.HttpServletResponse;
5import javax.servlet.http.HttpSession;
6
7import org.apache.struts.action.Action;
8import org.apache.struts.action.ActionForm;
9import org.apache.struts.action.ActionForward;
10import org.apache.struts.action.ActionMapping;
11
12import com.lingtu.tsgis.constant.StaticConst;
13import com.lingtu.tsgis.mapserver.MapFactory;
14import com.lingtu.tsgis.maptool.MapZoomInToolBean;
15import com.mapinfo.mapj.MapJ;
16
17/** *//**
18 * MyEclipse Struts Creation date: 02-16-2006
19 *
20 * XDoclet definition:
21 *
22 * @struts.action validate="true"
23 */
24public class MapservletAction extends Action {
25
26 // --------------------------------------------------------- Instance
27 // Variables
28
29 // --------------------------------------------------------- Methods
30
31 /** *//**
32 * Method execute
33 *
34 * @param mapping
35 * @param form
36 * @param request
37 * @param response
38 * @return ActionForward
39 */
40 public ActionForward execute(ActionMapping mapping, ActionForm form,
41 HttpServletRequest request, HttpServletResponse response) {
42 MapJ mainmap = null;
43 MapJ boudmap = null;
44 int toolnum = -1;
45
46 HttpSession session = request.getSession(true);
47 if (request.getParameter("toolnum") != null) {
48 try {
49 toolnum = new Integer(request.getParameter("toolnum"))
50 .intValue();
51 } catch (Exception e) {
52 toolnum = -1;
53 e.printStackTrace();
54 }
55 }
56 if (session.getAttribute(StaticConst.SESSION_MAINMAP) == null) {
57 try {
58 mainmap = new MapJ();
59 mainmap.loadMapDefinition("c:/Map/beijing.mdf");
60 } catch (Exception e) {
61 e.printStackTrace();
62 return mapping.findForward("gotoWrong");
63 }
64 } else {
65 mainmap = (MapJ) session.getAttribute(StaticConst.SESSION_MAINMAP);
66 }
67 switch (toolnum) {
68 case 0:
69 break;
70 case 1://缩小
71 break;
72 case 2://放大
73 MapZoomInToolBean zoomin=new MapZoomInToolBean();
74 zoomin.process(mainmap,request,new Double(5));
75 break;
76 }
77 MapFactory mapf = new MapFactory();
78 try {
79 mapf.ResponseMapIMG(mainmap, this.getServlet().getInitParameter(
80 "MapServerURL"), 800, 600, response);
81 session.setAttribute(StaticConst.SESSION_MAINMAP, mainmap);
82 return null;
83 } catch (Exception e) {
84 return mapping.findForward("gotoWrong");
85 }
86 }
87}