?? naviservlet.java
字號:
package mxtj45;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// declare imports////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// J2SE 1.3.1 importsimport java.io.IOException;import java.io.PrintWriter;import java.util.Enumeration;// J2EE 1.3.1 importsimport javax.servlet.*;import javax.servlet.http.*;// mxtj45. importsimport java.awt.*;import com.mapinfo.mapj.*;import com.mapinfo.mapxtreme.client.*;import com.mapinfo.util.*;import com.mapinfo.xmlprot.mxtj.*;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// top-level public class/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////** * simple servlet that performs zoom / pan operations on an MDF file defined * map, such that all map images are stored on the webserver as GIF files in a * publicly accessible context directory, and client state is maintained in * a servlet session with session ID values being conveyed via URL rewriting. * * @author John Dove, MapInfo Technical Support Department, 2002 */public class NaviServlet extends HttpServlet{ ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // fields ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------------- // static fields loaded as servlet initialization parameters //---------------------------------------------------------------------------- /** * absolute path of MDF file to load into all MapJ object. */ // REQUIRED IN WEB.XML static private String m_mdfFileToLoad; /** * url of the MapXtremeJava 4.5 servlet that is used for remote rendering. */ // REQUIRED IN WEB.XML static private String m_urlOfMapXtremeServlet; /** * directory to create GIF files in on webserver machine. These GIF images * will be referred to by URL links within the HTML documents returned to * clients. */ // REQUIRED IN WEB.XML static private String m_imageDirectory; /** * flag that indicates if all the servlet initialization parameters were * loaded upon servlet startup. */ static boolean m_allInitParamsLoaded; //---------------------------------------------------------------------------- // names of HTTP parameters that can be sent by client //---------------------------------------------------------------------------- /** * identifier for the http param that denotes the "type" of request sent by * a client. */ static private String m_param_requestType = "action"; /** * holds X-axis value of mouse click made by client on the map. */ static private String m_param_screenClickX = "map.x"; /** * holds Y-axis value of mouse click made by client on the map. */ static private String m_param_screenClickY = "map.y"; /** * http param value that denotes zoom-in operation. */ static private String m_requestZoomIn = "zin"; /** * http param value that denotes zoom-out operation. */ static private String m_requestZoomOut = "zout"; /** * http param value that denotes pan operation. */ static private String m_requestPan = "pan"; //---------------------------------------------------------------------------- // static fields with names for session stored objects //---------------------------------------------------------------------------- /** * name assigned to MapJ object when stored to session. */ static private String m_sessionNameForMapJ = "mapj"; /** * will be accessed via a synchronized code block to provide unique * incrementing long values on a per client-request basis */ static private long sequenceNumber; // defaults to zero ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // methods ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// public void init() throws ServletException { System.out.println("NAVI SERVLET INITIALIZING..."); // assume that all initialization parameters will NOT be loaded NaviServlet.m_allInitParamsLoaded = false; //-------------------------------------------------------------------------- // read the following initialization parameters, which should all be defined // in the deployment descriptor (web.xml) file of the web application that // this servlet is a part of. // // 1. mdfFileToLoad // 2. urlOfMapXtremeServlet // // if any of these parameters are NOT obtained, we will throw an exception. //-------------------------------------------------------------------------- m_mdfFileToLoad = this.getInitParameter("mdfFileToLoad"); m_urlOfMapXtremeServlet = this.getInitParameter("urlOfMapXtremeServlet"); m_imageDirectory = this.getInitParameter("imageDirectory"); System.out.println(""); System.out.println("SERVLET INIT PARAMETERS:"); System.out.println(" mdfFileToLoad = ["+m_mdfFileToLoad+"]"); System.out.println(" urlOfMapXtremeServlet = ["+m_urlOfMapXtremeServlet+"]"); System.out.println(" imageDirectory = ["+m_imageDirectory+"]"); System.out.println(""); if (m_mdfFileToLoad == null) { throw new ServletException("init param [mdfFileToLoad] was null."); } else if (m_urlOfMapXtremeServlet == null) { throw new ServletException("init param [urlOfMapXtremeServlet] was null."); } else if (m_imageDirectory == null) { throw new ServletException("init param [imageDirectory] was null."); } // if we made it here, it means all the needed init params were obtained NaviServlet.m_allInitParamsLoaded = true; } /** * handles HTTP GET requests. This method will execute in a separate thread * within the servlet container's JVM. * * @param req an HttpServletRequest object that contains the request the * client has made of the servlet * @param resp an HttpServletResponse object that contains the response the * servlet sends to the client * @throw java.io.IOException if an input or output error is detected when * the servlet handles the GET request * @throw ServletException if the request for the GET could not be handled * */ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,java.io.IOException { this.doPost(req,resp); } /** * handles HTTP POST requests. This method will execute in a separate thread * within the servlet container's JVM. * * @param req an HttpServletRequest object that contains the request the * client has made of the servlet * @param resp an HttpServletResponse object that contains the response the * servlet sends to the client * @throw java.io.IOException if an input or output error is detected when * the servlet handles the request * @throw ServletException - if the request for the POST could not be handled */ protected void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,java.io.IOException { String httpParam_requestType = null; // http param sent by client String httpParam_clickX = null; // http param sent by client String httpParam_clickY = null; // http param sent by client HttpSession clientSession = null; // client's session object MapJ mapj = null; // client's map-state object try { // throw exception if NOT all servlet init params were loaded on startup. // since this is the case, NO response will be sent back to the client. if (!NaviServlet.m_allInitParamsLoaded) { throw new ServletException("SOME SERVLET INIT PARAMS ARE MISSING."); } // read http parameters sent by client httpParam_requestType = req.getParameter(NaviServlet.m_param_requestType); httpParam_clickX = req.getParameter(NaviServlet.m_param_screenClickX); httpParam_clickY = req.getParameter(NaviServlet.m_param_screenClickY); //------------------------------------------------------------------------ // if NO request type http param was sent, we will assume this is the // client's FIRST request to this servlet //------------------------------------------------------------------------ if (httpParam_requestType == null)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -