?? frontcontroller.java
字號(hào):
package com.xyz.servlet;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.xyz.command.CmdDisplayLocation;
import com.xyz.command.CmdError;
import com.xyz.command.CmdHome;
import com.xyz.command.CmdRecordPurchases1;
import com.xyz.command.CmdRecordPurchases2;
import com.xyz.command.ICommand;
/**
* @version 1.0
* @author Lou Mauget
*/
public class FrontController extends HttpServlet implements ICommand {
/**
* @see com.xyz.command.ICommand#String (HttpServletRequest, HttpServletResponse)
*/
public String execute(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
return "";
}
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Enumeration enum = req.getParameterNames();
HashSet set = new HashSet();
while (enum.hasMoreElements())
set.add(enum.nextElement());
ICommand cmd = mapCommand(set);
String target = cmd.execute(req, resp);
req.getRequestDispatcher(target).forward(req, resp);
}
/**
* Returns an ICommand object corresponding to the passed
* command string in the set. Returns an error
* ICommand object if the string is null or unidentifiable
* @param set java.util.HashSet
*/
protected ICommand mapCommand(HashSet set) {
ICommand result = null;
if (set == null)
result = new CmdError();
else if (set.contains("CmdHome"))
result = new CmdHome();
else if (set.contains("CmdRecordPurchases1"))
result = new CmdRecordPurchases1();
else if (set.contains("CmdRecordPurchases2"))
result = new CmdRecordPurchases2();
else if (set.contains("CmdDisplayLocation"))
result = new CmdDisplayLocation();
else
result = new CmdError();
return result;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -