標準三層:資料層 (Java Control 封裝 SQL) → 邏輯層 (Page Flow Controller 處理業務與轉換) → 顯示層 (JSP + NetUI 標籤渲染)。清晰分離關注點,利於團隊並行開發。
<JDBCConnectionPool DriverName="oracle.jdbc.driver.OracleDriver"
LoginDelaySeconds="1" MaxCapacity="20" Name="liwei"
PasswordEncrypted="{3DES}..." Properties="user=liwei"
Targets="cgServer" URL="jdbc:oracle:thin:@localhost:1521:wincn"/>
<JDBCTxDataSource JNDIName="liwei" Name="liwei" PoolName="liwei" Targets="cgServer"/>
或透過 WebLogic 主控台圖形化建立。
package recordset;
import com.bea.control.*;
import java.sql.SQLException;
@ControlInterface
@JCConnection(dataSourceJndiName="liwei")
public interface TestControl extends DatabaseControl {
@JCSql(statement=
"INSERT INTO TEST (A,B,C,D) VALUES ({_A},{_B},{_C},{_D})")
int insert(String _A, String _B, String _C, String _D);
@JCSql(statement=
"UPDATE TEST SET B={_B}, C={_C}, D={_D} WHERE A={_A}")
int update(String _A, String _B, String _C, String _D);
@JCSql(statement="DELETE FROM TEST WHERE A={_A}")
int delete(String _A);
@JCSql(statement="SELECT * FROM TEST WHERE A={_A}")
TblTest select(String _A);
@JCSql(statement="SELECT * FROM TEST")
TblTest[] selectAll();
public static class TblTest implements java.io.Serializable {
public String A, B, C, D;
}
}
package recordset;
import com.bea.netuix.servlets.controls.pageflow.*;
public class RecordsetController extends PageFlowController {
@CommonControl private TestControl testCtrl;
private TestControl.TblTest[] dataCache;
private String toGb(String iso) {
try { return new String(iso.getBytes("ISO8859-1"), "GB2312"); }
catch (Exception e) { return ""; }
}
public TestControl.TblTest[] getAll() {
dataCache = testCtrl.selectAll();
for (TestControl.TblTest row : dataCache) {
row.A = toGb(row.A); row.B = toGb(row.B);
row.C = toGb(row.C); row.D = toGb(row.D);
}
return dataCache;
}
@Jpf.Action(forwards=@Jpf.Forward(name="success", path="index.jsp"))
public Forward add() {
testCtrl.insert(getRequest().getParameter("a"),
getRequest().getParameter("b"),
getRequest().getParameter("c"),
getRequest().getParameter("d"));
return new Forward("success");
}
@Jpf.Action(forwards=@Jpf.Forward(name="success", path="index.jsp"))
public Forward delete() {
testCtrl.delete(getRequest().getParameter("ToDelete"));
return new Forward("success");
}
@Jpf.Action(forwards=@Jpf.Forward(name="success", path="index.jsp"))
protected Forward begin() { return new Forward("success"); }
}
<%@ taglib prefix="netui" uri="https://bea.com/netui/tags" %>
<%@ taglib prefix="netui-data" uri="https://bea.com/netui/tags/databinding" %>
<body>
<table border="1">
<tr><th>A</th><th>B</th><th>C</th><th>D</th><th>操作</th></tr>
<netui-data:repeater dataSource="{pageFlow.all}">
<netui-data:repeaterItem>
<tr>
<td><netui:label value="{container.item.A}"/></td>
<td><netui:label value="{container.item.B}"/></td>
<td><netui:label value="{container.item.C}"/></td>
<td><netui:label value="{container.item.D}"/></td>
<td>
<netui:anchor action="delete" onClick="return confirm('刪除?')">
<netui:parameter name="ToDelete" value="{container.item.A}"/>
刪除
</netui:anchor>
</td>
</tr>
</netui-data:repeaterItem>
</netui-data:repeater>
</table>
<netui:form action="add">
A: <input name="a"/><br/>
B: <input name="b"/><br/>
C: <input name="c"/><br/>
D: <input name="d"/><br/>
<input type="submit" value="新增"/>
</netui:form>
</body>