[AppleScript] 纯文本查看 复制代码
public class UserServlet extends HttpServlet{
public void service(HttpServletRequest req,HttpServletResponse resp){
// 接收参数:
String methodName = request.getParameter(“method”);
if(“regist”.equals(methodName)){
regist(req,resp);
}else if(“login”.equals(methodName)){
login(req,resp);
}
}
public void regist(HttpServletRequest req,HttpServletResponse resp){
}
public void login(HttpServletRequest req,HttpServletResponse resp){
}
}
public class ProductServlet extends HttpServlet{
public void service(HttpServletRequest req,HttpServletResponse resp){
// 接收参数:
String methodName = request.getParameter(“method”);
if(“findAll”.equals(methodName)){
findAll(req,resp);
}else if(“findById”.equals(methodName)){
findById(req,resp);
}
}
public void findAll(HttpServletRequest req,HttpServletResponse resp){
}
public void findById(HttpServletRequest req,HttpServletResponse resp){
}
}
反射:
public class BaseServlet extends HttpServlet{
public void service(HttpServletRequest req,HttpServletResponse resp){
// http://localhost:8080/store_2.0/UserServlet?method=regist
// http://localhost:8080/store_2.0/ProductServlet?method=findAll
String methodName = request.getParameter(“method”);
// 获得Class:
Class clazz = this.getClass();
Method method = clazz.getMethod(methodName,HttpServletRequest.class,HttpSerlvetResponse.class);
String path = (String)method.invoke(this,req,resp);
if(path != null){
req.getRequestDispatcher(path).forward(req,resp);
}
}
}
public class UserServlet extends BaseServlet {
public String regist(HttpServletRequest req,HttpServletResponse resp){
return “/login.jsp”;
}
public String login(HttpServletRequest req,HttpServletResponse resp){
return “/index.jsp”;
}
}
public class ProductServlet extends BaseServlet{
public String findAll(HttpServletRequest req,HttpServletResponse resp){
}
public String findById(HttpServletRequest req,HttpServletResponse resp){
}
}