科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道基础软件WebLogic运用DB的Java控件访问数据库(2)

WebLogic运用DB的Java控件访问数据库(2)

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

本文讲解WebLogic运用DB的Java控件访问数据库的实现过程,具体内容包括:方法、建立连接池,数据源、相关页面、数据库、数据层(JAVA控件)、逻辑层(页面流)、显示层(页面)。

作者:草木瓜 来源:Csdn 2007年9月3日

关键字:

  • 评论
  • 分享微博
  • 分享邮件

六、逻辑层(页面流)



Test\TestWeb\recordset\RecordsetController.jpf 主要代码,省略了自动生成部分。

public class RecordsetController extends PageFlowController

{

/*

*

* @common:control

*/

private test recTest;       //定义数据接口

private test.tblTest[] recNew;  //定义数据集



//因为示例连接的是英文数据库,会存在乱码问题,下面是转码的函数,这也充分

//说明了,逻辑层在处理数据的关键所在。

private String getGBString(String strIn)

{

try

{  

byte[] tmpByte=strIn.getBytes("ISO8859-1");  

return new String(tmpByte,"gb2312");

}

catch(Exception e)

{

return "";

}

}

//返回全记录,调用recTest的selectAll,接口函数

public test.tblTest[] getAll()

{

recNew=recTest.selectAll();

int i;

for(i=0;i<recNew.length;i++)

{

recNew[i].A=getGBString(recNew[i].A);

recNew[i].B=getGBString(recNew[i].B);

recNew[i].C=getGBString(recNew[i].C);

recNew[i].D=getGBString(recNew[i].D);

}

return recNew;

}







//添加数据,这时通过页面传递的参数值,调用接口Add数据

/**

* @jpf:action

* @jpf:forward name="success" path="index.jsp"

*/

public Forward add()

{

recTest.insert(this.getRequest().getParameter("a"),

this.getRequest().getParameter("b"),this.getRequest().getParameter("c"),

this.getRequest().getParameter("d"));

return new Forward( "success" );

}



 //删除数据

/**

* @jpf:action

* @jpf:forward name="success" path="index.jsp"

*/

public Forward delete()

{

recTest.delete(this.getRequest().getParameter("ToDelete"));

return new Forward( "success");





/**

* 此方法代表进入页面流的入口

* @jpf:action

* @jpf:forward name="success" path="index.jsp"

*/

protected Forward begin()

{

return new Forward("success");

}

}

七、显示层(页面)

Test\TestWeb\recordset\index.jsp 最外层显示,查看下面完全代码时,可以看到netui控件的极大灵活性。



技术难点并不多,这里使用的是netui-data:repeater,重复获取记录集数据。

<body>

<table border=1>

<tr>

<td width="100" class="header-text">A</td>

<td width="100" class="header-text">B</td>

<td width="100" class="header-text">C</td>

<td width="100" class="header-text">D</td>

</tr>

<netui-data:repeater dataSource="{pageFlow.all}">

<netui-data:repeaterHeader> </netui-data:repeaterHeader>

<netui-data:repeaterItem>

<tr>

<td width="100" class="row-text"><a href="#"

onclick="window.alert('<netui:content

value='{container.item.A}-{container.item.B}-

{container.item.C}-{container.item.D}'/>')"><netui:label

value="{container.item.A}"/></a></td>

<td width="100" class="row-text"><netui:label

value="{container.item.B}"/></td>

<td width="100" class="row-text"><netui:label

value="{container.item.C}"/></td>

<td width="100" class="row-text"><netui:label

value="{container.item.D}"/></td>

<td>

<netui:anchor action="delete" onClick=

"return(window.confirm('Del?'))">

<netui:parameter name="ToDelete"

value="{container.item.A}"/>

Delete

</netui:anchor>

</td>

</tr>

</netui-data:repeaterItem>

<netui-data:repeaterFooter> </netui-data:repeaterFooter>

</netui-data:repeater>

</table>

<hr>

<netui:form action="add" >

A:<input type="text" name="a"/><br>

B:<input type="text" name="b"/><br>

C:<input type="text" name="c"/><br>

D:<input type="text" name="d"/><br>

<input type="submit" value="add">

</netui:form>

</body>   

 

八、小结

以前对java的了解为0,因项目迫切需要适当的研究下WebLogic,作为入门级的选手就能感受到WebLogic魅力的一二。清晰的层次非常便于组织项目的架构。页面流在Web开发过程可为核心,结合表示层的netui控件,将大量脚本可以化为简单轻松的面向对象的java语句。不管是前面提到的树形,还是本文的数据,随意而不零乱却是有机的整体。强!

感觉需要选本书系统的学习一下WebLogic的思想。

查看本文来源

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章