这是我自己开发的一个MVC框架
源代码在线查看: abstractform.java
package dark.web.frame.form;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dark.web.frame.Form;
import dark.web.frame.Helper;
import dark.web.frame.Message;
import dark.web.frame.Value;
import org.apache.log4j.Logger;
/**
* Title: 表单验证抽象类
* Description: 定义表单验证程序所必需的接口方法和公用方法
* Copyright: Copyright (c) 2004
* Company: DIS
* Create Time: 2004-12-6 0:17:20
* @author darkhe
* @version 1.0
*/
public abstract class AbstractForm implements Form
{
protected static Logger log = Logger.getLogger("DWF");
private ServletContext servletContext;
private HttpServletRequest request;
private HttpServletResponse response;
private Message message;
private String input;
/**
* 设置初始化参数,用于获取servlet上下文、请求和反馈
* @param context
* @param request
* @param response
*/
public void init(
ServletContext servletContext,
HttpServletRequest request,
HttpServletResponse response,
Message message)
{
this.servletContext = servletContext;
this.request = request;
this.response = response;
this.message = message;
}
/**
* @throws ServletException
* @throws IOException
*/
public void forward() throws ServletException, IOException
{
RequestDispatcher dispathcer =
servletContext.getRequestDispatcher(input);
dispathcer.forward(request, response);
}
/**
* 命令类的检证方法,default返回true,开发人员可根据具
* 体商来逻辑来重置当前方法的行为。只要当前返回true的情
* 况下,validate方法才被执行
* @return
* @throws ServletException
* @throws IOException
*/
public boolean isAuthentic() throws ServletException, IOException
{
return true;
}
/**
* 表单验证方法,子类必须实现当前方法已实现子类已经的具体的验证逻辑
* 开发人员应当将提示消息放入Message类。validate()方法返回的Message
* 对象的消息不为空则表明表单没有通过,此时控制器将会将请求转发到input
* 参数所指定的页面
* @throws ServletException
* @throws IOException
*/
public abstract Message validate() throws ServletException, IOException;
/**
* @return
*/
public HttpServletRequest getRequest()
{
return request;
}
/**
* @return
*/
public HttpServletResponse getResponse()
{
return response;
}
/**
* @return
*/
public ServletContext getServletContext()
{
return servletContext;
}
/**
* 返回请求转发路径
* @return
*/
public String getInput()
{
return input;
}
/**
* 设定请求转发路径
* @param string
*/
public void setInput(String string)
{
input = string;
}
/**
* @return
*/
public Message getMessage()
{
return message;
}
/**
* @param request
* @return
*/
public static Message loadMessage(HttpServletRequest request)
{
return Helper.loadMessage(request);
}
/**
* @param session
* @return
*/
public static Message loadMessage(HttpSession session)
{
return Helper.loadMessage(session);
}
/**
* @param request
* @return
*/
public static Value loadValue(HttpServletRequest request)
{
return Helper.loadValue(request);
}
/**
* @param session
* @return
*/
public static Value loadValue(HttpSession session)
{
return Helper.loadValue(session);
}
/**
* @param m
* @param request
*/
public static void saveMessage(Message m, HttpServletRequest request)
{
Helper.saveMessage(m, request);
}
/**
* @param m
* @param session
*/
public static void saveMessage(Message m, HttpSession session)
{
Helper.saveMessage(m, session);
}
/**
* @param v
* @param request
*/
public static void saveValue(Value v, HttpServletRequest request)
{
Helper.saveValue(v, request);
}
/**
* @param v
* @param session
*/
public static void saveValue(Value v, HttpSession session)
{
Helper.saveValue(v, session);
}
}