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

📄 actionservlet.java

📁 Java协同办公系统。实现公司内部的人事
💻 JAVA
字号:
package com.icss.oa.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class ActionServlet extends HttpServlet {

	Properties properties = null;
	public void init(){
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		
		try {
			DocumentBuilder db = dbf.newDocumentBuilder();
		
			Document doc = db.parse(this.getServletContext().getResourceAsStream("/WEB-INF/conf.xml"));
			
		
			NodeList lists = doc.getElementsByTagName("action");
			
			properties = new Properties();

			for(int len = 0;len<lists.getLength();len++){
				
				Element e = (Element) lists.item(len);
	
				String actionName = e.getElementsByTagName("action-name").item(0).getFirstChild().getNodeValue();
				
				String actionType = e.getElementsByTagName("action-type").item(0).getFirstChild().getNodeValue();
					
				properties.put(actionName, actionType);
				
			}
			
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		HttpSession session = request.getSession();
		
		String path = request.getRequestURI();

		int i = path.lastIndexOf("/");
		
		int j = path.lastIndexOf(".");
		
		String realPath = path.substring(i+1,j);
		
		Action action = null;

		try {
			
			String 	actionPath = properties.getProperty(realPath);
			
			action = (Action) Class.forName(actionPath).newInstance();

		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		action.execute(request, response);
	
	}


}

⌨️ 快捷键说明

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