什麼也不說了,相對簡單,直接上代碼
package org.J.v;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.J.c.Action;
/**
* 1.普通返回指向頁面 ([a-zA-Z]|$)+ extends 轉發
* 2.重定向 r:([a-zA-Z]|$)+ r:/([a-zA-Z]|$)+
* 3.轉發 d:([a-zA-Z]|$)+ d:/([a-zA-Z]|$)+
* r:redirect 重定向 response.sendRedirect(view);
* r(1)> return 'r:action1'
* r(2)> return 'r:/action1'
* d:dispatcher request.getRequestDispatcher(view).forward(request,response);
* d(1)> return 'd:action1' 指向本命名空間下的action1
* d(2)> return 'd:/test/action2' 指向命名空間根目錄的action2
*
* @author Gelopa
*
*/
public abstract class View{
/**返回path*/
protected String view;
protected transient HttpServletRequest request;
protected transient HttpServletResponse response;
protected Action actionInstance;
protected File file;//具體展現的物理文件
protected Object actionResultObj;//action返回值對象
protected static final String gen="/";//根目錄
protected static final String r$normal="([a-zA-Z]|$)+";
protected static final String r$redirectThisNamespace="r:([a-zA-Z]|$)+";
protected static final String r$redirectOtherNamespace="r:/([a-zA-Z]|$)+";
protected static final String d$dispatcherThisNamespace="d:([a-zA-Z]|$)+";
protected static final String d$dispatcherOtherNamespace="d:/([a-zA-Z]|$)+";
public abstract void render();
public abstract View handlerAfterAction();
public View(){}
public View(String view, HttpServletRequest request,HttpServletResponse response) {
this.view = view;
this.request = request;
this.response = response;
}
public String getView() {
return view;
}
public void setView(String view) {
this.view = view;
}
private Map<String,Object> dataInSession=new HashMap<String, Object>();
public Map<String, Object> getAttrsInSession() {
return dataInSession;
}
public void addDataInSession(String attr,Object value){
dataInSession.put(attr, value);
}
public void delDataInSession(String attr,Object value){
dataInSession.remove(attr);
}
public Action getActionInstance() {
return actionInstance;
}
public void setActionInstance(Action actionInstance) {
this.actionInstance = actionInstance;
}
}
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.J.c.Action;
/**
* 1.普通返回指向頁面 ([a-zA-Z]|$)+ extends 轉發
* 2.重定向 r:([a-zA-Z]|$)+ r:/([a-zA-Z]|$)+
* 3.轉發 d:([a-zA-Z]|$)+ d:/([a-zA-Z]|$)+
* r:redirect 重定向 response.sendRedirect(view);
* r(1)> return 'r:action1'
* r(2)> return 'r:/action1'
* d:dispatcher request.getRequestDispatcher(view).forward(request,response);
* d(1)> return 'd:action1' 指向本命名空間下的action1
* d(2)> return 'd:/test/action2' 指向命名空間根目錄的action2
*
* @author Gelopa
*
*/
public abstract class View{
/**返回path*/
protected String view;
protected transient HttpServletRequest request;
protected transient HttpServletResponse response;
protected Action actionInstance;
protected File file;//具體展現的物理文件
protected Object actionResultObj;//action返回值對象
protected static final String gen="/";//根目錄
protected static final String r$normal="([a-zA-Z]|$)+";
protected static final String r$redirectThisNamespace="r:([a-zA-Z]|$)+";
protected static final String r$redirectOtherNamespace="r:/([a-zA-Z]|$)+";
protected static final String d$dispatcherThisNamespace="d:([a-zA-Z]|$)+";
protected static final String d$dispatcherOtherNamespace="d:/([a-zA-Z]|$)+";
public abstract void render();
public abstract View handlerAfterAction();
public View(){}
public View(String view, HttpServletRequest request,HttpServletResponse response) {
this.view = view;
this.request = request;
this.response = response;
}
public String getView() {
return view;
}
public void setView(String view) {
this.view = view;
}
private Map<String,Object> dataInSession=new HashMap<String, Object>();
public Map<String, Object> getAttrsInSession() {
return dataInSession;
}
public void addDataInSession(String attr,Object value){
dataInSession.put(attr, value);
}
public void delDataInSession(String attr,Object value){
dataInSession.remove(attr);
}
public Action getActionInstance() {
return actionInstance;
}
public void setActionInstance(Action actionInstance) {
this.actionInstance = actionInstance;
}
}