JAVA网页编程之Jsp分页原代码,及用法
进而能拉拢大多数程序员用windows产品。并且从ASP.NETAJAX可以跨平台这一点上,间接证明了我们的推断,至少证明了微软做过这方面的研究。所以如果哪一天突然听说了.net可以跨平台了,那么请不要吃惊,如果这一天真的到来,java就到了真正和.net决战的时刻。因为不到万不得以的时候微软是不会推出跨平台的.net的,如果跨平台的.net还不足以对抗java的话,那么微软还剩的手段就是开源了,呵呵。js|分页Jsp分页原代码,及用法1.界说一个分页的TagBean,以便用户在Jsp页中利用自界说标签,用户在利用时能够响应的形貌
packageBSC.tree;
importjavax.servlet.jsp.*;
importjavax.servlet.jsp.tagext.*;
importjavax.servlet.jsp.tagext.TagSupport;
importjavax.servlet.http.HttpServletResponse;
importorg.apache.struts.action.ActionServlet;
importjava.sql.*;
importBSC.pool.*;
importjava.util.*;
//importjava.util.regex.Pattern;
importpubBean.Patten;
importBSC.tree.pagetag.*;
/**
*@author丁小龙(DingXiaolong)
*@version1.1
*@deprecated可以经由过程SQL语句发生一个GRID而且可经由过程响应的CSS设置响应的属性
*@paramstrSQL必要实行的查询SQL语句
*@parampageSizeGrid每页所生的纪录行数(Row)
*@paramaction当点分页素引号码所要跳转的页面称号,必需是利用本标记页面的称号
*@paramstyle全部Grid的CSS的CLASS的设置
*@paramctrPageBeanSessionNM外部利用
*@parampageTileBeanSessionNM未利用,暂保存
*@paramdatabeanNM存储Grid一切数据汇合,假如和ScriptTag对应的标记类适用时分,必需与其name利用不异值
*@paramloginIndexSessionNM存储物理数据与逻辑数据的索引对应的汇合称号,假如和ScriptTag对应的标记类适用时分,必需与其loginIndexSessionNM利用不异值
*@paramcaptionGrid表头题目,各列(Col)的题目用逗号(",")离隔,且数目必需和SQL语句所列出的字段分歧
*@paramisHiddenGrid各列是不是显现(0--显现,1--为不显现),各列(Col)是不是显现值用逗号(",")离隔,且数目必需和SQL语句所列出的字段分歧
*@paramtrStyleGrid各行的CSS设置值
*@paramtableWidthGrid表的宽度,能够是相对值的表达体例,也能够是绝对值的表达体例
*@paramtdWidthGrid各列(col)之宽度,各列(Col)宽度用逗号(",")离隔,且数目必需和SQL语句所列出的字段分歧
*@paramdatabase在Sturts-config中设置的datasourcekey名
*/
publicclassPageScriptTag
extendsBodyTagSupport{
privateStringstrSQL;
privateStringpageSize="1";
privateStringaction;
privateStringstyle;
privateStringcurrentSize="1";
privateStringctrPageBeanSessionNM;
privateStringpageTileBeanSessionNM;
privateStringdisplayCol;
privateStringlogicIndex;
privateStringdatabeanNM;
privateStringloginIndexSessionNM;
privateStringcaption;
privateStringisHidden;
protectedstaticintscope=2;
privateStringtrStyle;
privateStringheadTrStyle;
privateStringheadTdStyle;
privateStringtdStyle;
privateStringtableWidth;
privateStringtdWidth;
privateStringurlPara;
privateStringoddTrStyle;//Grid奇行css的class设置
privateStringevenTrStyle;
privateStringdatabase;//Grid奇行css的class设置
publicPageScriptTag(){
}
publicStringgetAction(){
returnaction;
}
publicStringgetCtrPageBeanSessionNM(){
returnctrPageBeanSessionNM;
}
publicStringgetCurrentSize(){
returncurrentSize;
}
publicStringgetDisplayCol(){
returndisplayCol;
}
publicStringgetPageSize(){
returnpageSize;
}
publicStringgetPageTileBeanSessionNM(){
returnpageTileBeanSessionNM;
}
publicStringgetStrSQL(){
returnstrSQL;
}
publicStringgetStyle(){
returnstyle;
}
publicvoidsetStyle(Stringstyle){
this.style=style;
}
publicvoidsetStrSQL(StringstrSQL){
this.strSQL=strSQL;
}
publicvoidsetPageTileBeanSessionNM(StringpageTileBeanSessionNM){
this.pageTileBeanSessionNM=pageTileBeanSessionNM;
}
publicvoidsetPageSize(StringpageSize){
this.pageSize=pageSize;
}
publicvoidsetDisplayCol(StringdisplayCol){
this.displayCol=displayCol;
}
publicvoidsetCurrentSize(StringcurrentSize){
this.currentSize=currentSize;
}
publicvoidsetCtrPageBeanSessionNM(StringctrPageBeanSessionNM){
this.ctrPageBeanSessionNM=ctrPageBeanSessionNM;
}
publicvoidsetAction(Stringaction){
this.action=action;
}
publicintdoEndTag()throwsjavax.servlet.jsp.JspException{
/**@todoOverridethisjavax.servlet.jsp.tagext.BodyTagSupportmethod*/
System.out.println("InClassPageScriptTagsdoEndTag");
System.out.println("Thescopeis"+this.scope);
Connectionconn=null;
//本类能够参考自己宣布的“界说本人的ConnectionPool”
PoolBeandatasource=null;
try{
//初始化数据库毗连
//失掉数据库入手下手,用户可使用本人的毗连池类datasource=(PoolBean)pageContext.getAttribute(this.getDatabase(),3);
if(datasource==null){
DB_Operatedb_oper=newDB_Operate();
datasource=db_oper.getDataSource(this.getDatabase());
}
conn=datasource.getConnection();
//失掉数据库停止
PattenstrP=newPatten();
if(getStrSQL()!=null){
strP.compile("<");
String[]strsqlarr=strP.split(getStrSQL());
Stringtmpstr="";
StringstrLink="";
for(intstrI=0;strI<strsqlarr.length;strI++)
{
tmpstr+=strLink+strsqlarr;
strLink="<";
}
this.setStrSQL(tmpstr);
}
System.out.println(this.getStrSQL());
PageDataBeandatabean=(PageDataBean)this.pageContext.getAttribute(
getDatabeanNM(),scope);
if(databean==null){
databean=newPageDataBean(this.getStrSQL(),conn);
}
else{
if(databean.getIsFlg().equals("0")){
databean.setStrSQL(this.getStrSQL());
databean.init(conn);
System.out.println("InitialingthePageDataBean.........");
databean.setIsFlg("1");
}
}
intcolCount=(newInteger(databean.getColCount())).intValue();
JspWriterout=this.pageContext.getOut();
StringtmpDis=this.getDisplayCol();
//Patten类参考我宣布的“java正则表达式”
Pattenp=newPatten();
p.compile(",");
StringctrPageBeanNM;
if(this.getCtrPageBeanSessionNM()==null){
ctrPageBeanNM="CTRPAGE";
}
else{
ctrPageBeanNM=getCtrPageBeanSessionNM();
}
CtrPageBeanctrpge=(CtrPageBean)pageContext.getAttribute(ctrPageBeanNM,
scope);
Vectordatas=databean.getDataList();
Hashtabledataarry=databean.getDataArray();
if(ctrpge==null){
ctrpge=newCtrPageBean(datas.size()+"",getPageSize());
}
StringtmpLoginIndexSessionNM="";
if(this.getLoginIndexSessionNM()==null){
tmpLoginIndexSessionNM="tmpLoginIndexSessionNM";
}
else{
tmpLoginIndexSessionNM=this.getLoginIndexSessionNM();
//前往的材料库本栏位入手下手的地位
}
intcolcapstar=databean.getColnameindex().size()-colCount;
//初始化是不是要埋没
StringtmpIsHidden=this.getIsHidden();
String[]tmpIsHiddenArray=p.split(tmpIsHidden);
for(inthidindex=colcapstar;
hidindex<tmpIsHiddenArray.length+colcapstar;hidindex++){
databean.getIsHiddenArray().put((String)databean.getColnameindex().
elementAt(hidindex),
tmpIsHiddenArray);
}
//初始化Grid的题目
StringtmpCaption=this.getCaption();
String[]tmpCaptionArr=p.split(tmpCaption);
for(intcapindex=colcapstar;
capindex<tmpCaptionArr.length+colcapstar;capindex++){
databean.getCaptionArray().put((String)databean.getColnameindex().
elementAt(capindex),
tmpCaptionArr);
}
//初奴化Grid各col的宽度
Stringtdwidflg="0";
StringtmpWidth=this.getTdWidth();
if(tmpWidth!=null){
String[]tmpWidthArr=p.split(tmpWidth);
for(intwidindex=colcapstar;
widindex<tmpWidthArr.length+colcapstar;widindex++){
databean.getWidthArray().put((String)databean.getColnameindex().
elementAt(widindex),
tmpWidthArr);
}
tdwidflg="1";
}
String[]tmpLogicIndexs=null;
VectorlogicIndexs=(Vector)pageContext.getAttribute(
tmpLoginIndexSessionNM,scope);
if(logicIndexs==null){
logicIndexs=newVector();
}
if(this.getLogicIndex()!=null){
tmpLogicIndexs=p.split(this.getLogicIndex());
if(tmpLogicIndexs.length!=colCount){
intoldsize=logicIndexs.size();
logicIndexs.removeAllElements();
for(inti=1;i<=colCount+oldsize;i++){
inttmp=i-1;
logicIndexs.addElement(""+tmp);
}
}
else{
for(inti=1;i<=colCount;i++){
logicIndexs.addElement(""+tmpLogicIndexs);
}
}
}
else{
intoldsize=logicIndexs.size();
logicIndexs.removeAllElements();
for(inti=1;i<=colCount+oldsize;i++){
inttmp=i-1;
logicIndexs.addElement(""+tmp);
}
}
HashtableScriptObj=newHashtable();
HashtableCaptionObj=newHashtable();
HashtableisHiddenObj=newHashtable();
HashtablewidthObj=newHashtable();
HashtableTDObj=newHashtable();
for(inti=0;i<logicIndexs.size();i++){
//intlgcIndex=newInteger((String)logicIndexs.elementAt(i)).intValue();
Stringcolkey=(String)databean.getColnameindex().elementAt(i);
StringlgcIndex=(String)logicIndexs.elementAt(i);
CaptionObj.put(lgcIndex,databean.getCaptionArray().get(colkey));
isHiddenObj.put(lgcIndex,databean.getIsHiddenArray().get(colkey));
widthObj.put(lgcIndex,databean.getWidthArray().get(colkey));
if(colkey.indexOf("Script,,,")==-1){
if(databean.getDataArray().get(colkey)!=null){
ScriptObj.put(lgcIndex,databean.getDataArray().get(colkey));
TDObj.put(lgcIndex,colkey);
}
}
else{
StringstrScript=(String)databean.getDataArray().get(colkey);
VectorvecScript=newVector();
for(intk=0;k<databean.getDataList().size();k++){
vecScript.addElement(strScript);
}
ScriptObj.put(lgcIndex,vecScript);
TDObj.put(lgcIndex,"Script___");
}
}
ctrpge.setCurrent(getCurrentSize());
intstart=(ctrpge.getInteger(ctrpge.getCurrent())-1)*
ctrpge.getInteger(ctrpge.getPageSize());
intoffset=(ctrpge.getInteger(ctrpge.getCurrent()))*
ctrpge.getInteger(ctrpge.getPageSize());
out.print("<tableborder="0"cellspacing="1"");
if(this.getTableWidth()!=null){
out.print("width=""+this.getTableWidth()+""");
}
if(this.getStyle()!=""){
out.print("class="");
out.print(style);
out.print(""");
}
out.println(">");
out.print("<tr");
if(this.getHeadTrStyle()!=null)
out.println("class=""+this.getHeadTrStyle()+"">");
for(intcapindex=0;capindex<CaptionObj.size();capindex++){
out.print("<tdalign=center");
if(((String)isHiddenObj.get(""+capindex)).equals("1")){
out.print("style="display:none"");
}
if(tdwidflg.equals("1")){
out.print("width=""+(String)widthObj.get(""+capindex)+""");
}
if(this.getHeadTdStyle()!=null)
out.print("class=""+this.getHeadTdStyle()+"">");
out.println(">");
out.println((String)CaptionObj.get(""+capindex));
out.println("</td>");
}
out.println("</tr>");
intRec_count=0;
for(inti=start,k=0;i<offset&&i<datas.size();k++,i++){
Stringtdstyle="td";
out.println("<trid=TmpGridID_"+k+"style=cursor:hand");
out.print("onMouseOver="f_onclick(this,"+k+","+ScriptObj.size()+
")"");
if(k%2==0&&this.getEvenTrStyle()!=null){
out.print("class="");
out.print(this.getEvenTrStyle()+""");
}
if(k%2!=0&&this.getOddTrStyle()!=null){
out.print("class="");
out.print(this.getOddTrStyle()+""");
}
if(this.getTrStyle()!=null&&this.getEvenTrStyle()==null&&k%2==0){
out.print("class="");
out.print(this.getTrStyle()+""");
}
if(this.getTrStyle()!=null&&this.getOddTrStyle()==null&&k%2!=0){
out.print("class="");
out.print(this.getTrStyle()+""");
}
out.print(">");
for(intj=0;j<ScriptObj.size();j++){
Vectortdvalues=(Vector)ScriptObj.get(""+j);
Stringtd_id=(String)TDObj.get(""+j);
out.print("<tdalign=left");
out.print("id=TD_"+td_id+"_"+i+"_"+j+"");
if(((String)isHiddenObj.get(""+j)).equals("1")){
out.print("style="display:none"");
}
if(this.getTdStyle()!=null){
out.print("class="");
out.print(this.getTdStyle()+""");
}
out.println(">");
Stringtdval=(String)tdvalues.elementAt(i);
if(!td_id.equals("Script___")){
out.println("<inputtype=hiddenid=TDVal_"+td_id+"_"+k+
"value="+tdval+">");
}
out.println(tdval);
out.println("</td>");
}
out.println("</tr>");
Rec_count++;
}
out.println("<inputtype=hiddenname=TmpGrid_RecordCountvalue="+
Rec_count+">");
out.println("</table>");
//输入分页检索的页码
Stringhyperlink=null;
if(ctrpge.getInteger(ctrpge.getMax())>1&&this.getAction()!=null){
hyperlink=((HttpServletResponse)pageContext.getResponse()).
encodeURL(this.getAction());
if(hyperlink!=null){
out.println("<br>");
out.println
(
"<tablewidth=100%border="0"cellspacing="0"cellpadding="0"");
/*if(style!=""){
out.println("class="");
out.println(style);
out.println(""");
}*/
out.print(">");
out.println("<tr>");
out.println("<tdalign=centerwidth=10%>");
out.print("共"+ctrpge.getMax()+"页");
out.print("以后为第"+ctrpge.getCurrent()+"页");
out.println("页数检索:");
out.print("<ahref="");
Stringpropmt="";
if(this.getAction().indexOf(?)==-1){
propmt="?";
}
out.print(hyperlink);
out.print(propmt+"index="+1);
out.print(""");
out.print(">");
out.print("[第一页]");
out.print("</a>");
out.println("");
out.print("<ahref="");
out.print(hyperlink);
out.print(propmt+"index="+ctrpge.getLast());
if(this.getUrlPara()!=null){
out.print("&"+this.getUrlPara());
}
out.print(""");
out.print(">");
out.print("上一页");
out.print("</a>");
out.println("");
intindexmax=ctrpge.getInteger(ctrpge.getMax());
intindexcur=ctrpge.getInteger(ctrpge.getCurrent());
intindexstart=indexcur-indexcur%10+1;
intindexoffect=indexcur-indexcur%10+10;
for(intmindex=indexstart;
mindex<=indexoffect&&mindex<=indexmax;mindex++){
out.print("<ahref="");
out.print(hyperlink);
out.print(propmt+"index="+mindex);
if(this.getUrlPara()!=null){
out.print("&"+this.getUrlPara());
}
out.print(""");
out.print(">");
out.print(mindex);
out.print("</a>");
out.println("");
}
out.print("<ahref="");
out.print(hyperlink);
out.print(propmt+"index="+ctrpge.getNext());
if(this.getUrlPara()!=null){
out.print("&"+this.getUrlPara());
}
out.print(""");
out.print(">");
out.print("下一页");
out.print("</a>");
out.println("");
out.print("<ahref="");
out.print(hyperlink);
out.print(propmt+"index="+ctrpge.getMax());
if(this.getUrlPara()!=null){
out.print("&"+this.getUrlPara());
}
out.print(""");
out.print(">");
out.print("[最末页]");
out.print("</a>");
out.println("");
out.println("</td>");
out.println("</tr>");
out.println("</table>");
}
}
pageContext.setAttribute(ctrPageBeanNM,ctrpge,scope);
pageContext.setAttribute(tmpLoginIndexSessionNM,logicIndexs,scope);
}
catch(Exceptione){
System.out.println("PageScriptTagError:"+e.getMessage());
}
finally{
try{
if(conn!=null)
conn.close();
}catch(SQLExceptionsqle){
sqle.printStackTrace();
}
}
returnsuper.doEndTag();
}
publicStringgetLogicIndex(){
returnlogicIndex;
}
publicvoidsetLogicIndex(StringlogicIndex){
this.logicIndex=logicIndex;
}
publicStringgetDatabeanNM(){
returndatabeanNM;
}
publicvoidsetDatabeanNM(StringdatabeanNM){
this.databeanNM=databeanNM;
}
publicStringgetLoginIndexSessionNM(){
returnloginIndexSessionNM;
}
publicvoidsetLoginIndexSessionNM(StringloginIndexSessionNM){
this.loginIndexSessionNM=loginIndexSessionNM;
}
publicStringgetCaption(){
returncaption;
}
publicvoidsetCaption(Stringcaption){
this.caption=caption;
}
publicStringgetIsHidden(){
returnisHidden;
}
publicvoidsetIsHidden(StringisHidden){
this.isHidden=isHidden;
}
publicStringgetTrStyle(){
returntrStyle;
}
publicvoidsetTrStyle(StringtrStyle){
this.trStyle=trStyle;
}
publicStringgetHeadTrStyle(){
returnheadTrStyle;
}
publicvoidsetHeadTrStyle(StringheadTrStyle){
this.headTrStyle=headTrStyle;
}
publicStringgetHeadTdStyle(){
returnheadTdStyle;
}
publicvoidsetHeadTdStyle(StringheadTdStyle){
this.headTdStyle=headTdStyle;
}
publicStringgetTdStyle(){
returntdStyle;
}
publicvoidsetTdStyle(StringtdStyle){
this.tdStyle=tdStyle;
}
publicStringgetTableWidth(){
returntableWidth;
}
publicvoidsetTableWidth(StringtableWidth){
this.tableWidth=tableWidth;
}
publicStringgetTdWidth(){
returntdWidth;
}
publicvoidsetTdWidth(StringtdWidth){
this.tdWidth=tdWidth;
}
publicStringgetUrlPara(){
returnurlPara;
}
publicvoidsetUrlPara(StringurlPara){
this.urlPara=urlPara;
}
publicStringgetOddTrStyle(){
returnoddTrStyle;
}
publicvoidsetOddTrStyle(StringoddTrStyle){
this.oddTrStyle=oddTrStyle;
}
publicStringgetEvenTrStyle(){
returnevenTrStyle;
}
publicvoidsetEvenTrStyle(StringevenTrStyle){
this.evenTrStyle=evenTrStyle;
}
publicStringgetDatabase(){
returndatabase;
}
publicvoidsetDatabase(Stringdatabase){
this.database=database;
}
}
2.界说次TagBean,它是一个用出现特别html组件,如text,button等
packageBSC.tree;
importjavax.servlet.jsp.*;
importjavax.servlet.jsp.tagext.*;
importjavax.servlet.jsp.tagext.TagSupport;
importjavax.servlet.http.HttpServletResponse;
importjava.sql.*;
importjava.util.*;
importpubBean.*;
importBSC.tree.pagetag.*;
publicclassScriptTag
extendsBodyTagSupport{
privateStringname;
privateStringproperty;
privateStringvalue;
privateStringindex;
privateStringloginIndexSessionNM;
privateStringcaption;
privateStringisHidden;
protectedstaticintscope=2;
privateStringwidth;
publicScriptTag(){
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetProperty(){
returnproperty;
}
publicvoidsetProperty(Stringproperty){
this.property=property;
}
publicStringgetValue(){
returnvalue;
}
publicvoidsetValue(Stringvalue){
this.value=value;
}
publicintdoEndTag()throwsjavax.servlet.jsp.JspException{
/**@todoOverridethisjavax.servlet.jsp.tagext.BodyTagSupportmethod*/
System.out.println("InClassScriptTagsdoEndTag()");
try{
System.out.println("Thescopeis"+this.scope);
PageDataBeandatabean=(PageDataBean)this.pageContext.getAttribute(this.
getName(),scope);
VectorlogicIndexs=(Vector)this.pageContext.getAttribute(this.
getLoginIndexSessionNM(),scope);
if(databean==null){
System.out.println("CreatetheDataBean...");
databean=newPageDataBean();
}
if(logicIndexs==null){
logicIndexs=newVector();
}
logicIndexs.addElement(this.getIndex());
databean.getColnameindex().addElement("Script,,,"+this.getProperty());
databean.getDataArray().put("Script,,,"+this.getProperty(),
this.getValue());
databean.getCaptionArray().put("Script,,,"+this.getProperty(),
this.getCaption());
databean.getIsHiddenArray().put("Script,,,"+this.getProperty(),
this.getIsHidden());
databean.getWidthArray().put("Script,,,"+this.getProperty(),
this.getWidth());
pageContext.setAttribute(this.getName(),databean,scope);
pageContext.setAttribute(this.getLoginIndexSessionNM(),logicIndexs,
scope);
}
catch(Exceptione){
System.out.println("ScriptTagError:"+e.getMessage());
}
returnsuper.doEndTag();
}
publicStringgetIndex(){
returnindex;
}
publicvoidsetIndex(Stringindex){
this.index=index;
}
publicStringgetLoginIndexSessionNM(){
returnloginIndexSessionNM;
}
publicvoidsetLoginIndexSessionNM(StringloginIndexSessionNM){
this.loginIndexSessionNM=loginIndexSessionNM;
}
publicStringgetCaption(){
returncaption;
}
publicvoidsetCaption(Stringcaption){
this.caption=caption;
}
publicStringgetIsHidden(){
returnisHidden;
}
publicvoidsetIsHidden(StringisHidden){
this.isHidden=isHidden;
}
publicStringgetWidth(){
returnwidth;
}
publicvoidsetWidth(Stringwidth){
this.width=width;
}
}
3.界说一个用于实行sql查询语句,并将响应的数保留到该Bean内里
packageBSC.tree.pagetag;
importjava.sql.*;
importjava.util.*;
publicclassPageDataBean{
privateVectordataList=newVector();
privateStringstrSQL="";
privateStringcolCount="0";
privatejava.util.HashtabledataArray=newHashtable();
privatejava.util.Vectorcolnameindex=newVector();
privatejava.util.HashtablecaptionArray=newHashtable();
privatejava.util.HashtableisHiddenArray=newHashtable();
privateStringisFlg="0";
privatejava.util.HashtablewidthArray=newHashtable();
publicPageDataBean(StringstrSQL,Connectionconn){
this.setStrSQL(strSQL);
init(conn);
}
publicPageDataBean(){
}
publicVectorgetDataList(){
returndataList;
}
protectedvoidsetDataList(java.util.VectordataList){
this.dataList=dataList;
}
publicStringgetStrSQL(){
returnstrSQL;
}
publicvoidsetStrSQL(StringstrSQL){
this.strSQL=strSQL;
}
publicvoidinit(Connectionconn){
try{
//Statementstat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Statementstat=conn.createStatement();
ResultSetrs=stat.executeQuery(this.getStrSQL());
ResultSettmrs=null;
if(rs!=null){
intcolcount=rs.getMetaData().getColumnCount();
this.setColCount(""+colcount);
intreccount=0;
while(rs.next()){
reccount++;
VectorrowDate=newVector();
for(inti=1;i<=colcount;i++){
rowDate.addElement(notNull(rs.getString(i)));
}
this.getDataList().addElement(rowDate);
}
for(inti=1;i<=colcount;i++){
this.getColnameindex().addElement(rs.getMetaData().getColumnName(i));
}
if(reccount!=0){
for(inti=1;i<=colcount;i++){
//rs.first();
tmrs=stat.executeQuery(this.getStrSQL());
Vectorcols=newVector();
while(tmrs.next()){
cols.addElement(notNull(tmrs.getString(i)));
}
this.addNode(tmrs.getMetaData().getColumnName(i),cols);
tmrs.close();
}
}
}
}catch(Exceptione){
System.out.print("PageDataBeanError:"+e.getMessage());
}
}
publicStringgetColCount(){
returncolCount;
}
protectedvoidsetColCount(StringcolCount){
this.colCount=colCount;
}
publicjava.util.HashtablegetDataArray(){
returndataArray;
}
publicvoidsetDataArray(java.util.HashtabledataArray){
this.dataArray=dataArray;
}
voidaddNode(Stringname,Objectobj)throwsIllegalArgumentException{
synchronized(dataArray){
if(dataArray.containsKey(name))
thrownewIllegalArgumentException("Columnname"+name+
"isnotunique");
dataArray.put(name,obj);
}
}
voidaddCaptionNode(Stringname,Stringobj)throwsIllegalArgumentException{
synchronized(captionArray){
if(dataArray.containsKey(name))
thrownewIllegalArgumentException("Columnname"+name+
"isnotunique");
captionArray.put(name,obj);
}
}
publicjava.util.VectorgetColnameindex(){
returncolnameindex;
}
publicvoidsetColnameindex(java.util.Vectorcolnameindex){
this.colnameindex=colnameindex;
}
publicjava.util.HashtablegetCaptionArray(){
returncaptionArray;
}
publicvoidsetCaptionArray(java.util.HashtablecaptionArray){
this.captionArray=captionArray;
}
publicjava.util.HashtablegetIsHiddenArray(){
returnisHiddenArray;
}
publicvoidsetIsHiddenArray(java.util.HashtableisHiddenArray){
this.isHiddenArray=isHiddenArray;
}
publicStringgetIsFlg(){
returnisFlg;
}
publicvoidsetIsFlg(StringisFlg){
this.isFlg=isFlg;
}
publicjava.util.HashtablegetWidthArray(){
returnwidthArray;
}
publicvoidsetWidthArray(java.util.HashtablewidthArray){
this.widthArray=widthArray;
}
/**
*notNull
*
*@paramaStrString
*/
publicStringnotNull(StringaStr){
if(aStr!=null)
returnaStr.trim();
else
return"";
}
}
4.界说一个主控类,用于保留分页Grid的页面信息
packageBSC.tree.pagetag;
publicclassCtrPageBean{
privateStringnext="1";
privateStringlast="1";
privateStringcurrent="1";
privateStringsize="0";
privateStringmax="1";
privateStringpageSize="0";
publicCtrPageBean(Stringsize,StringpageSize){
if(this.getInteger(size)!=0){
if(this.getInteger(pageSize)<0)
this.setPageSize(size);
this.setSize(size);
this.setPageSize(pageSize);
if(this.getInteger(pageSize)>this.getInteger(size)){
this.setPageSize(size);
}
if(pageSize=="0")
this.setPageSize("1");
intleval=this.getInteger(getSize())%this.getInteger(this.getPageSize());
intmaxv=0;
if(leval==0){
maxv=this.getInteger(getSize())/this.getInteger(this.getPageSize());
}
else{
maxv=this.getInteger(getSize())/this.getInteger(this.getPageSize())+
1;
}
this.setMax(""+maxv);
}
}
publicStringgetMax(){
returnmax;
}
protectedvoidsetMax(Stringmax){
this.max=max;
}
publicStringgetNext(){
returnnext;
}
publicvoidsetNext(Stringnext){
this.next=next;
}
publicStringgetLast(){
returnlast;
}
publicvoidsetLast(Stringlast){
this.last=last;
}
publicStringgetCurrent(){
returncurrent;
}
publicvoidsetCurrent(Stringcurrent){
this.current=current;
if(this.getInteger(this.getCurrent())==this.getInteger(this.getMax())){
this.setNext("1");
}
else{
intcur=getInteger(this.current)+1;
this.setNext(""+cur);
}
if(this.getInteger(this.getCurrent())!=1){
intlastv=getInteger(this.current)-1;
this.setLast(""+lastv);
}
else
this.setLast("1");
}
publicStringgetSize(){
returnsize;
}
protectedvoidsetSize(Stringsize){
this.size=size;
}
protectedvoidinit(Stringsize){
}
publicStringgetPageSize(){
returnpageSize;
}
publicvoidsetPageSize(StringpageSize){
this.pageSize=pageSize;
}
publicintgetInteger(Stringval){
Integervals=newInteger(val);
returnvals.intValue();
}
}
5.界说一个名叫page_table.tld的tld文件,并将其寄存到WEB-INF目次下内容
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEtaglibPUBLIC"-//SunMicrosystems,Inc.//DTDJSPTagLibrary1.1//EN""http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>PAGETABLE</shortname>
<uri>helloworld</uri>
<info>OUTTABLE</info>
<tag>
<name>ScriptTag</name>
<tagclass>BSC.tree.ScriptTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>property</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>index</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>loginIndexSessionNM</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>caption</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>isHidden</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>width</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!--attribute>
<name>isFlush</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute-->
</tag>
<tag>
<name>PageScriptTag</name>
<tagclass>BSC.tree.PageScriptTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>strSQL</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>pageSize</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>action</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>style</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>currentSize</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>ctrPageBeanSessionNM</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>pageTileBeanSessionNM</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>displayCol</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>loginIndexSessionNM</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>logicIndex</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>databeanNM</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>caption</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>isHidden</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>trStyle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>tdStyle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>headTrStyle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>headTdStyle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>tableWidth</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>tdWidth</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>urlPara</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>oddTrStyle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>evenTrStyle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>database</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
6.在jsp中利用,
<%@pagecontentType="text/html;charset=Big5"%>
<%@tagliburi="/WEB-INF/struts-bean.tld"prefix="bean"%>
<%@tagliburi="/WEB-INF/struts-html.tld"prefix="html"%>
<%@tagliburi="/WEB-INF/struts-logic.tld"prefix="logic"%>
<%@tagliburi="/WEB-INF/page_table.tld"prefix="pagetab"%>
<%@pageimport="BSC.pool.*"%>
<html>
<head>
<title>
login
</title>
<linkhref="css/wfr_css.css"rel="stylesheet"type="text/css"></head>
<scriptlanguage="JavaScript"src="js/PubFun.js"type="text/javascript"></script>
</head>
<bodybgcolor="#ffffff">
<logic:presentname="userManageForm">
<bean:writename="userManageForm"property="email"/>
</logic:present>
<logic:notPresentname="userManageForm">
addddddddddd
</logic:notPresent>
<!--bean:writename="userManageForm"property="email"/-->
<%
//以下就是发生分页Grid的代码
Stringindex="1";
index=request.getParameter("index");
if(index==null)
index="1";
%>
<pagetab:PageScriptTag
logicIndex="0,1"
pageSize="10"
isHidden="0,0"
action="TestGrid.jsp"
style="outtable"
currentSize="<%=index%>"
strSQL="selectttid,TypefromTrans_Type"
databeanNM="databeanname"
loginIndexSessionNM="loginIndexSessionNM"
caption="县市ID,县市称号"
headTrStyle="text1"
tdWidth="5%,20%"
database="resources.SQLServerDB"
/>
</body>
</html>
因为能用到多少功能就用多少,不能用就不用!总的来说:要简单要性能好,可以不用框架。你说java复杂,就是因为你把java(j2ee)与这些框架混在了一起。 你就该学一学Servlet了。Servlet就是服务器端小程序,他负责生成发送给客户端的HTML文件。JSP在执行时,也是先转换成Servlet再运行的。虽说JSP理论上可以完全取代Servlet,这也是SUN推出JSP的本意,可是Servlet用来控制流程跳转还是挺方便的,也令程序更清晰。接下来你应该学习一下Javabean了,可能你早就看不管JSP在HTML中嵌Java代码的混乱方式了,这种方式跟ASP又有什么区别呢? 是一种由美国SUN计算机公司(Sun Microsystems, Inc.)所研究而成的语言 任职于太阳微系统的詹姆斯·高斯林等人于1990年代初开发Java语言的雏形,最初被命名为Oak,目标设置在家用电器等小型系统的程序语言 接着就是EJB了,EJB就是Enterprise JavaBean, 看名字好象它是Javabean,可是它和Javabean还是有区别的。它是一个体系结构,你可以搭建更安全、更稳定的企业应用。它的大量代码已由中间件(也就是我们常听到的 Weblogic,Websphere这些J2EE服务器)完成了,所以我们要做的程序代码量很少,大部分工作都在设计和配置中间件上。 Jive的资料在很多网站上都有,大家可以找来研究一下。相信你读完代码后,会有脱胎换骨的感觉。遗憾的是Jive从2.5以后就不再无条件的开放源代码,同时有licence限制。不过幸好还有中国一流的Java程序员关注它,外国人不开源了,中国人就不能开源吗?这里向大家推荐一个汉化的Jive版本—J道。Jive(J道版)是由中国Java界大名 鼎鼎的banq在Jive 2.1版本基础上改编而成, 全中文,增加了一些实用功能,如贴图,用户头像和用户资料查询等,而且有一个开发团队在不断升级。你可以访问banq的网站 Java语言支持Internet应用的开发,在基本的Java应用编程接口中有一个网络应用编程接口(java net),它提供了用于网络应用编程的类库,包括URL、URLConnection、Socket、ServerSocket等。Java的RMI(远程方法激活)机制也是开发分布式应用的重要手段。 其实说这种话的人就如当年小日本号称“三个月拿下中国”一样大言不惭。不是Tomjava泼你冷水,你现在只是学到了Java的骨架,却还没有学到Java的精髓。接下来你得研究设计模式了。 Sun公司看见Oak在互联网上应用的前景,于是改造了Oak,于1995年5月以Java的名称正式发布。Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。 任职于太阳微系统的詹姆斯·高斯林等人于1990年代初开发Java语言的雏形,最初被命名为Oak,目标设置在家用电器等小型系统的程序语言 Sun公司看见Oak在互联网上应用的前景,于是改造了Oak,于1995年5月以Java的名称正式发布。Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。 是一种使网页(Web Page)由静态(Static)转变为动态(Dynamic)的语言 http://www.jdon.com/去下载,或到同济技术论坛的服务器ftp://nro.shtdu.edu.cn去下,安装上有什么问题,可以到论坛上去提问。 应用在电视机、电话、闹钟、烤面包机等家用电器的控制和通信。由于这些智能化家电的市场需求没有预期的高,Sun公司放弃了该项计划。随着1990年代互联网的发展 另外编写和运行Java程序需要JDK(包括JRE),在sun的官方网站上有下载,thinking in java第三版用的JDK版本是1.4,现在流行的版本1.5(sun称作J2SE 5.0,汗),不过听说Bruce的TIJ第四版国外已经出来了,是专门为J2SE 5.0而写的。 Sun公司看见Oak在互联网上应用的前景,于是改造了Oak,于1995年5月以Java的名称正式发布。Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。 多重继承(以接口取代)等特性,增加了垃圾回收器功能用于回收不再被引用的对象所占据的内存空间,使得程序员不用再为内存管理而担忧。在 Java 1.5 版本中,Java 又引入了泛型编程(Generic Programming)、类型安全的枚举、不定长参数和自动装/拆箱等语言特性。 http://www.jdon.com/去下载,或到同济技术论坛的服务器ftp://nro.shtdu.edu.cn去下,安装上有什么问题,可以到论坛上去提问。 另外编写和运行Java程序需要JDK(包括JRE),在sun的官方网站上有下载,thinking in java第三版用的JDK版本是1.4,现在流行的版本1.5(sun称作J2SE 5.0,汗),不过听说Bruce的TIJ第四版国外已经出来了,是专门为J2SE 5.0而写的。
页:
[1]