網頁開發MVC模式使用手冊
------作者:albert cheng
1、頁面a必然對應三個文檔,分別爲a.htm, a.xml, a.jsp
2、點擊頁面調用的是a.jsp文檔,然後在a.jsp的最上面
<1>用以下代碼來判斷權限:
<%
RightJudger rightjudger=(RightJudger)session.getAttribute("Privilege");
if ((rightjudger==null) || (rightjudger.hasRight("consumer_accredit_qry")==false))
{
if(rightjudger==null){
response.sendRedirect("/public/outtime.htm");
}else{
response.sendRedirect("/public/privilegeless.htm");
}
return;
}
%>
<2>用以下代碼來得到界面上的值:
String id = request.getParameter("id");
String code = request.getParameter("code");
String name = request.getParameter("name");
<3>用以下代碼來把界面上得到的參數傳入xml中,並且把得到的數據返回到一個數據集中來
//產生一個"參數對象",把得到的數據傳入其中
Parameters param = new Parameters();
param.put("caproduct_id", id);
param.put("caproduct_code", code);
param.put("caproduct_name", isoToGBK(name));
//把得到的參數傳入*.xml,用Engine打開一個數據集,並得到返回的值
//下面一句綁定了a.jsp和product目錄下的"a.xml"模型文件
DataSet ds0 = Engine.openDataSet( "product.a", param, InterfaceSystem.getDataSource() );
DataSet ds1 = Engine.mapToDataSet(param,"URL");
<3>下面的代碼綁定了a.jsp和a.htm文件
//構造了一個向量,並把上面查詢回來的數據集放入
Vector vec = new Vector();
vec.add( ds0 );
vec.add( ds1 );
//把返回的數據集和templete目錄下的templete目錄下的a.htm綁定起來,替換其中的標記
Html fmt = new Html();
htmlText = fmt.bind(getTemplatePath()+"template//a.htm", vec );
用這種模式來開發網頁,不但業務,顯示,控制分離,而且開發進度可控,非常好使,強烈推薦。
當然也可以用hibernate+ struct+ spring,也是一樣的:)