?? myservlet.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 + -