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

📄 myservlet.java

📁 订餐系统
💻 JAVA
字号:
package Control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import Biz.*;


public class myServlet extends HttpServlet {

	private Map map;
	public myServlet(){
		super();
		map = new HashMap();
		putCommand();
	}

	public void putCommand()
	{
		map.put("login", new loginImp());
		map.put("register",new registerImp());
		map.put("add", new AddFoodToCart());
	}
	public void destroy() {
		super.destroy();
	}


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

	}


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

		response.setContentType("text/html");
		String flag = (String) request.getParameter("flag");
		System.out.println("flag="+flag);
		String path = "";
		try
		{
			//map.get(flag)通过标识来获取相对应的Command()
			BizInterface command = (BizInterface)map.get(flag);
			//调用子类的execute方法来获取返回页面
			path = command.execute(request, response);
		}catch(Exception ex)
		{
			request.setAttribute("message", new Exception("找不到相关类"));
			path = "message.jsp";
		}	
		request.getRequestDispatcher(path).forward(request, response);
	
	}


	public void init() throws ServletException {
	
	}

}

⌨️ 快捷键说明

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