⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serverroot.java

📁 银行项目为后台socket通信写的程序
💻 JAVA
字号:
package com.ecSolutions.ecAppServer.management;

import org.apache.log4j.Logger;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.ServletHttpContext;

import com.ecSolutions.ecAppServer.Configuration;
import com.ecSolutions.ecAppServer.ecAppServerConfigException;
import com.ecSolutions.ecAppServer.config.PropertiesConfiguration;

public class ServerRoot {
	private static Logger log = Logger.getLogger("ServerRoot");	

	private static final String CONTEXT_PATH = "/ecAppserver";

	private static final String SERVLET_CLASS = "com.ecSolutions.ecAppServer.management.LoginServlet";

//	private static final String SERVLET_CLASS1 = "com.ecSolutions.ecAppServer.management.CheckPassword";

	private static final String SERVLET_CLASS2 = "com.ecSolutions.ecAppServer.management.ValidUser";

	private static final String SERVLET_PATH = "/admin";

	private static final String SERVLET_MAPPING = SERVLET_PATH + "/*";

//	private static final String SERVLET_MAPPING1 = "/manage" + "/CheckPassword";

	private static final String SERVLET_MAPPING2 = "/manage" + "/ValidUser";

	private static Server manageServer = null;
	
	public static void main(final String[] args) {
		startAppWebServer();
	} 

	public static void startAppWebServer() {
		
		String LISTEN_ADDR = null;
		Configuration config = null;
		try {
			config = PropertiesConfiguration.getInstance();
			LISTEN_ADDR = config.getString("HostIP") + ":" + config.getString("adminPort");
		} catch (ecAppServerConfigException e) {
			log.error(e);
		}

		try {

			// represents a container
			manageServer = new Server();

			// configure container to listen on a given socket for requests
			manageServer.addListener(LISTEN_ADDR);

			// define a web application at a given context path
			ServletHttpContext ctx = (ServletHttpContext) manageServer.getContext(CONTEXT_PATH);

			// map a servlet class to a URI
			ctx.addServlet("LoginServlet", SERVLET_MAPPING, SERVLET_CLASS);
			//ctx.addServlet("CheckPassword", SERVLET_MAPPING1, SERVLET_CLASS1);
			ctx.addServlet("ValidUser", SERVLET_MAPPING2, SERVLET_CLASS2);
			// start the container.  Notice that this call returns immediately;
			// Jetty handles the threading for you behind the scenes.  All you
			// have to do is hold on to the Server object such that you can 
			// shut it down later.

			manageServer.start();
			System.out.println("Server started");

		} catch (Throwable t) {
			t.printStackTrace();
			log.error(t);
		}
		
		

	}
	
	
	
	public static void stopAppWebServer() {
		try {
			manageServer.stop();
		} catch (InterruptedException e) {
			log.error(e.toString());
		}
	}
	
	
	

} // public class Step1Driver

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -