页面自动跳转问题、项目计划书

    昨天,应开发小组顾问linzc的建议,我增加了提交日记后的选择去向功能。方法是把原来的提交方法:

boolean postArticle()  的返回参数改为代表提交日记的id,即int类型,然后把它的parentArtID和它的

postedArtID在request里传给跳转页面就行了。但是,本来想延迟3秒自动跳到提交后的日记中,但是我不会

,还是寻找方法,希望知道的朋友在这里提一下。

    我已经尝到了写程序没有文档的苦头,就这么一个东西,我要添加什么的时候,看自己以前写的程序都花

了我大部分时间。看来,文档是太重要了。

    昨天,给小组全体成员发了一封信,增加了我们的迟到的文档维护队队长kula的资料,并把章程和这个月

的成员名单寄给了大家,提请大家审定。

    这两天还是把项目计划书写好,交给几个管理的朋友审定一下,再发到网上请大家审定。

    现在,我们单位的工地开工了,我投入到这个项目的时间多少会有影响,但我会挤出时间来为开发小组的

顺利开展工作服好务。

    我们的顾问linzc为我们的工作提了许多好的建议,并且把他的解决问题的日记写出来供大家分享。在这里

,我要向他表示深深的感谢。并顺祝他身体健康、工作顺利、万事如意!他写的eclipse+easystruts的日记对

我有很大的学习价值,我推荐像我这样的初学好好看一下他的日记。

action 与form

阿! 终于写完了action ,看起来并没有什么新的东西可以拿来展览,呵呵  您列代码如下

 STRUTS ACTION

// Created by Xslt generator for Eclipse.

// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))

// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.phone.struts.action;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import java.io.InputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.io.FileOutputStream;

import java.io.File;

import java.sql.*;

import javax.sql.*;

import com.phone.struts.form.FileloadForm;

import org.apache.struts.upload.FormFile;

import com.phone.struts.javabean.excelReadBean;

/**

 * FileloadAction.java created by EasyStruts - XsltGen.

 * http://easystruts.sf.net

 * created on 11-21-2004

 *

 * XDoclet definition:

 * @struts:action path="/fileload" name="fileloadForm" input="/form/fileload.jsp" validate="true"

 * @struts:action-forward name="success.jsp" path="success.jsp"

 * @struts:action-forward name="fail.jsp" path="fail.jsp"

 */

public class FileloadAction extends Action {

// --------------------------------------------------------- Instance Variables

private String fodler=null;

// --------------------------------------------------------- Methods

/**

* Method execute

* @param ActionMapping mapping

* @param ActionForm form

* @param HttpServletRequest request

* @param HttpServletResponse response

* @return ActionForward

* @throws Exception

*/

public ActionForward execute(

ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws Exception {

//Start from here  

 

  Connection conn = null;

      FileloadForm fileloadForm = (FileloadForm) form;

      String fname=fileloadForm.getFileName();

      if(!uploadFile( mapping,  form, request,response))

      {

      System.out.println("upload file failed");

      return mapping.findForward("fail");

      }

      System.out.println("file upload successful");

      excelReadBean readBean=new excelReadBean();

      DataSource dataSource = (DataSource)servlet.getServletContext().getAttribute(

  "org.apache.struts.action.DATA_SOURCE");

  conn = dataSource.getConnection();

readBean.read("test",fodler + "/"+fname,conn);

return mapping.findForward("success");

}

/***

* this function is used to upload file

* @param mapping

* @param form

* @param request

* @param response

*/

public boolean uploadFile(ActionMapping mapping, ActionForm form,

   HttpServletRequest request,

   HttpServletResponse response)

{     

FileloadForm hff = (FileloadForm) form;

if(fodler == null)

  {

  ActionForward test = (ActionForward)mapping.findForward("pathFile");

  fodler = test.getPath();

  }

  if (fodler == null){

  fodler =this.getServlet().getServletContext().getRealPath("/WEB-INF");

  }

  if (fodler != null){

  fodler = fodler.replace('\\', '/').replace('/', File.separatorChar);

  }

  FormFile file = hff.getFile();

  if (file == null ) {

System.out.println("error : file  is null");

return false;

}

// Get the name and file size

String fname = file.getFileName();

String size = Integer.toString(file.getFileSize()) + " bytes";

try{

InputStream streamIn = file.getInputStream();

OutputStream streamOut=null;

streamOut = new FileOutputStream(fodler + "/"+fname);

  int bytesRead = 0;

  byte[] buffer = new byte[8192];

   while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {

streamOut.write(buffer, 0, bytesRead);

   }

  streamOut.close();

  streamIn.close();

}catch(IOException e)

{

System.out.println("IoException:"+e);

}

// Populate the form bean with the results for display in the View

hff.setFileName(fname);

hff.setFileSize(size);

// Clean up our toys when done playing

file.destroy();

    return true;

}

}

可以看到uploadFile()方法用力完成,将客户端的文件上传到,服务器上,而在我们的,主程序里,我们完成了对他的调用,随后调用readBean.read("test",fodler + "/"+fname,conn);完成将xls文件读入数据库.呵呵,初步的轮廓就如此了,可惜要更实用,你必须靠率很多问题,而在此,我想,做个简单的例子,到不用兴师动众。

STRUTS FORM

// Created by Xslt generator for Eclipse.

// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))

// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.phone.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.upload.FormFile;

import org.apache.struts.action.ActionError;

/**

 * FileloadForm.java created by EasyStruts - XsltGen.

 * http://easystruts.sf.net

 * created on 11-21-2004

 *

 * XDoclet definition:

 * @struts:form name="fileloadForm"

 */

public class FileloadForm extends ActionForm {

// --------------------------------------------------------- Instance Variables

/** fileName property */

private String fileName;

/** file property */

private FormFile file;

/** fileSize property */

private String fileSize;

    private boolean isSave;

// --------------------------------------------------------- Methods

/**

* Method validate

* @param ActionMapping mapping

* @param HttpServletRequest request

* @return ActionErrors

*/

public ActionErrors validate(

ActionMapping mapping,

HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

  if (file == null ) {

errors.add("file", new ActionError("error.file"));

  }

  return errors;

}

/**

* Method reset

* @param ActionMapping mapping

* @param HttpServletRequest request

*/

public void reset(ActionMapping mapping, HttpServletRequest request) {

fileName = "";

file = null;

fileSize = "";

        isSave=false;

}

/**

* Returns the fileName.

* @return String

*/

public String getFileName() {

return fileName;

}

/**

* Set the fileName.

* @param fileName The fileName to set

*/

public void setFileName(String fileName) {

this.fileName = fileName;

}

/**

* Returns the file.

* @return FormFile

*/

public FormFile getFile() {

return file;

}

/**

* Set the file.

* @param file The file to set

*/

public void setFile(FormFile file) {

this.file = file;

}

/**

* Returns the fileSize.

* @return String

*/

public String getFileSize() {

return fileSize;

}

/**

* Set the fileSize.

* @param fileSize The fileSize to set

*/

public void setFileSize(String fileSize) {

this.fileSize = fileSize;

}

/**

* @return

*/

public boolean isSave() {

return isSave;

}

/**

* @param b

*/

public void setSave(boolean b) {

isSave = b;

}

}

感觉的出来,注释竟然比程序还占空间,呵呵 感谢xslt 为我们提供了自动转换的方法, 呵呵虽然我还是懒得完成注释,

好久没有玩xsl了,会不会手生呢?

好了最后就是jsp页面了

 <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<%@ page contentType="text/html; charset=GB2312" %>

<html:html>

<body bottommargin="15" topmargin="15" leftmargin="15" rightmargin="15" marginheight="15" marginwidth="15" bgcolor="white" >

<link rel="stylesheet" type="text/css" media="all" href="<%=request.getContextPath()%>/styles/style.css" />

<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/selectbox.js"></script>

<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/global.js"></script>

<title>文件上传:</title>

</head>

<body bottommargin="15" topmargin="15" leftmargin="15" rightmargin="15" marginheight="15" marginwidth="15" bgcolor="white">

<h1>文件上传:</h1>

<!--

        The most important part is to declare your form's enctype

        to be "multipart/form-data", and to have an html:file

        element that maps to your ActionForm's FormFile property

-->

 <html:form action="//fileload.do" enctype="multipart/form-data" >

   

    <html:file property="file" /><html:errors property="file"/></p>

   

    <html:submit />

    </p>

    </html:form>

<p>

</body>

</html:html>

呵呵,html标签为我们提供了简单方面的操作,可惜很多美化工作,还是得借助css,要知道,我总是很

愤恨它,因为它丑陋的各式,为什么就没fo支持呢?还得用,javascript,我总庆幸我不会写,script,

这样总是让我免予帮别人写页面,可惜也因此我不得不依赖别人,copy它们的js.

好像剩下的工作就剩下,调试了,如果你在看,对你确实如此,可是,我的考虑它的应用环境,呵呵,也学我根本

就不需要上传,假如,再本级工作! 不管怎么说,STRUTS下的开发还是这么的快,真的,以前也会被杂乱的jsp,和

servlet搞得头昏脑胀,呵呵   我想该睡个好觉去了!

一周回顾

原计划这个周末考试数据库,可惜被通知推迟了。这样一来,我的进度加快了。

从jsp语法到el,可谓是“大跃进”了。

这本书的第五章讲述了隐含对象,Implicit object,

我在阅读的时候发现知识太凌乱,可能因为我太心急,不求甚解。

看了第六章el的知识,这种感觉更强烈。

顺便看了第六章JSTL,明白了我原先使用tablib报错的原因了。

btw:自己被授命“顾问”,还真有点,,

嘿嘿,一定努力!!

好了,今天好累,先睡

希望英语之:戏剧

戏剧:drama

How to learn colloquialism(口语)?

The answer is watch english DVD etc.

tragedy 悲剧

Juliet 朱丽叶  (youngthful)

go round  到处走动

semphony 交响乐

round three 第三场

parrot 鹦鹉

carrot 胡萝卜

penguin 企鹅 

struts下开发

休息来一早上,现在来吧poi应用移植到struts下,周末快结束了,我必须迅速了结这个任务

,为了简单开发,我还是用eclipse2.1+easy struts ,恩如果你正在我的日记,(实际上,我倒是一直努力将它写成一个给初学者的实例教程)并对easy struts插件不是很了解,你应该先看看"使用 Easy Struts for Eclipse 开发 Struts "这篇文章(在网站内我已经给过它的连接),现在我的各种插件已经配置完成,  开始开发吧!!

 1 ,创建一个tomcat应用,并添加easy struts 支持,看过文章后 这很使简单。

 2 ,创建一个fileuploadfom  and fileuploadbean   ,还是很简单,唯一要提及的form 属性:

     FormFile file;   String fileName; String size;   恩如果你在提示里找不到FormFile 这个类请在类型里键入

     org.apache.struts.upload.FormFile 他关联的html标签相应的是html:file;接着你应该修改一下,formbean

     的reset函数,

  3,恩,还需要给函数加上验证,加入一下代码!同时在propertie 文件中加入error.file 消息

   ActionErrors errors = new ActionErrors();

    if (file == null )

       {

          errors.add("file", new ActionError("error.file")); 

       }

     return errors;

 4, 在我写action志前,我应当将poitest.java 进行修改以适应action的调用,首先在我们的项目文件里加入

    javabean包!现在声成一个javabean excelReadBean,显然它的目的,一眼就可以看出来。

    现在把poitest.java 的read(String table) 方法的代码拷贝过来,恩很显然,少了全局变量:xlsfile(参照原     代码);这里不得不注意这样的问题,为了满足,线程无关性,将read方法变为,read(String table,String xlsfile);

    现在似乎完成了,然而,我们不准备使用,手动连接,为了更方便以后更改,现在来吧数据源放在struts的配置文件里,(参照"使用 Easy Struts for Eclipse 开发 Struts ",现在来完成 DATABASE配置)

  5,既然,要通过Struts框架连接数据库,我想我们的代码也应改修改一下,不过我总是期望以后再次使用这个类,也许并不在Struts框架下,所以我决定使用夺态,在建一个read方法(懒家伙总是向我这样)。

   public boolean read(String table,String xslfile,Connection conn)

{

return false;

} // 为此又不得不引进,sql包,

   现在有理由相信,里面很简单,我们要做的仅仅是将同明方法的代码拷过来!然后删除,曾在上文提及的Rs方法,因为我们用不着他了,加入一下代码:

   Statement stmt = null;

   boolean   rs= false;

  然后将,rs.execute(sql.toString())替换为

  stmt=conn.createStatement();rs=stmt.execute(sql.toString()); 最后return rs;  好一切噢可!如果不想再改观这个类,我想这份工作已经完成了,可是我还是一个类200多行的代码,就是冗余阿,还是修改修改 恩,把读和写剥离开,就这枚简单!  现在来看看修改了后的javabean,  代码又和以前差不多了,呵呵,功能却没有减

/*

 * Created on 2004-11-21

 *

 * To change the template for this generated file go to

 * Window>Preferences>Java>Code Generation>Code and Comments

 */

package com.phone.struts.javabean;

 

import java.io.*;

import java.util.*;

import javax.sql.*;

import java.sql.*;

import org.apache.poi.hssf.usermodel.*;

import org.apache.poi.hssf.model.*;

import org.apache.poi.poifs.filesystem.*;

import com.cims.db.*;

/**

 * @author Administrator

 *

 * To change the template for this generated type comment go to

 * Window>Preferences>Java>Code Generation>Code and Comments

 */

public class excelReadBean {

public excelReadBean()

{

}

/**

*

* @param table  this is the name of table in databse

* @param xslfile the excel file which you want to deel with

* @return

*/

public boolean read(String table,String xslfile)

{  

boolean   rs= false;

   rs=read(table,xslfile,null);

return rs;

}

/**

*

* @param table

* @param xslfile

* @param conn

* @return

*/

public boolean read(String table,String xslfile,Connection conn)

{

//@rs for the the result of executing sql

boolean   rs= false;

//construts a poifile

POIFSFileSystem fs=null;

HSSFWorkbook   wb=null; 

try

{

fs =new POIFSFileSystem(new FileInputStream(xslfile));

wb= new HSSFWorkbook(fs);

}catch(IOException e)

{

System.out.println("io exception :"+e);

}

HSSFSheet sheet = wb.getSheetAt(0);

//

System.out.println("the sheet name of  poifile="+wb.getSheetName(0));

int rownum=sheet.getPhysicalNumberOfRows();

System.out.println("the physical Number of rows="+rownum);

for(int rowflag=1;rowflag<rownum;rowflag++)

{

      //enter into row loop

      HSSFRow row = sheet.getRow(rowflag);

      int cells = row.getPhysicalNumberOfCells();

      System.out.println("the total number of cell in this row"+cells);

      System.out.println("this ROW= " + row.getRowNum());

            

      //

      String cellV[]=new String[cells];

      for(int cellflag=0;cellflag<cells;cellflag++)

  {

         //enter into cell loop

                 

         HSSFCell  cell= row.getCell((short)cellflag);

         double    valuenum = 0;

         String    valuestr=null;

         String    type=null;

// i got the code below from org.apache.poi.hssf.dev.hssf class

// and modify some

switch (cell.getCellType())

{

                             case HSSFCell.CELL_TYPE_FORMULA :

      type = "FORMULA ";

      valuestr="null";

  break;

case HSSFCell.CELL_TYPE_NUMERIC :

type = "NUMERIC";

valuenum=cell.getNumericCellValue();

break;

case HSSFCell.CELL_TYPE_STRING :

type = "STRING";

valuestr=cell.getStringCellValue();

break;

   default :

type=null;

}

if(type!=null)

{

System.out.print("the type of this cell is==="+type);

if(valuestr!=null)

{

cellV[cellflag]=valuestr.trim();

System.out.println("the value of this cell is==="+valuestr);

  } else  

  {

  cellV[cellflag]=Double.toString(valuenum);

  System.out.println("the value of this cell is==="+valuenum);

  }

} else

{

  cellV[cellflag]="null";

  System.out.println("erro in the file ,there is a null type cell :"+cellflag);

}

  }

  //here i will manipulate the 'insert' directive of database

  StringBuffer sql=new StringBuffer("insert into "+table+"  values (");

  for(int j=1;j<cells;j++)

  {

sql.append("'"+cellV[j-1]+"',");

  }

  sql.append("'"+cellV[cells-1]+"','"+rowflag+"')");

  System.out.println("sql  "+"="+sql.toString());

//call the write() function

      if(conn!=null)

  {

       rs=this.write(conn,sql.toString());

  }else

        rs=this.write(sql.toString());

     

}

return rs;

}

/**

*

* @param conn  the jdbc connection

* @param sql   the sentence of sql

* @return

*/

private boolean write(Connection conn,String sql)

{

Statement stmt = null;

boolean   rs= false;

try{ 

System.out.println("Start connet to db");

             stmt=conn.createStatement();

         rs=stmt.execute(sql.toString());

        }catch(Exception e)

        {

                 System.out.println("  sql exception "+e);

        }

return rs;

}

/**

*

* @param sql

* @return

*/

private boolean write(String sql)

    {

Rs  resultset=new Rs();

    boolean   rs= false;

    try



   System.out.println("Start connet to db");

           rs=resultset.execute(sql.toString());

}catch(Exception e)

    {

System.out.println("  sql exception "+e);

}

return rs;

}

}

写数据库

晚饭过后,终于有了点精神,顺便把写数据库给做了,这么小的程序就用jdbc吧! 呵呵省力!!!

首先引进import com.cims.db.*;包,其中封装了两个类,conn(创立连接),rs(执行sql)

呵呵接着在 row 循环里续代码了

  /**

   *  below i will connection the database and execute the sql .

              **/

              try

              { 

                    System.out.println("Start connet to db");

                   

                   

                   

                    resultset.execute(sql.toString());

              }catch(Exception e)

              {

                   

                    System.out.println("  sql exception "+e);

              }

就这几行了,所有的数据库操作已经简单封装在被引用的包里。 呵呵  如果您在看我的日记 不是很名白com.cims.db.*

拿酒来看看它中的代码吧!

  conn:  一个创立连接的类  它提供了getConnection方法返回一个connection

  public Connection getConnection() throws SQLException,IOException

{  

String url=null;

String username=null;

    String password=null;

   Connection conn=null;

   Properties props=new Properties();  

   InputStream in = getClass().getResourceAsStream("/database.properties");

   props.load(in);

   System.out.println("hello2");

   in.close();    

    try{

String drivers=props.getProperty("jdbc.drivers");

System.out.println(drivers);

if (drivers!=null)

    Class.forName(drivers).newInstance();

    System.out.println("test for url");

url=props.getProperty("jdbc.url");

System.out.println(url);

username=props.getProperty("username");

password=props.getProperty("password");

System.out.println(password);

   }

   catch(Exception e){System.out.println(e.getMessage());}

   return DriverManager.getConnection(url,username,password);

}

   Rs :sql执行类 其中

      public ResultSet executeQuery(String sql) throws SQLException,IOException方法用于

     数据库查询

      public int executeUpdate(String sql) throws SQLException,IOException 用于数据更新

     当然,还用更通用的方法

     public boolean execute (String sql) throws SQLException,IOException 让他来完成我们的

    数据插入

   看看conn 你就会发现使用jdbc怎么配置数据源了 呵呵  来看看MySQL数据库下配置数据源 

   database.properties的代码:

     jdbc.drivers=org.gjt.mm.mysql.Driver

     jdbc.url=jdbc:mysql://localhost:3306/crm

     username=root

     password=cimserp

  如果你使用的是oracle, 拿酒看看下面例子

    jdbc.drivers=oracle.jdbc.driver.OracleDriver

    jdbc.url=jdbc:oracle:thin:@10.11.12.46:1521:cimserp

    username=cimserp

    password=cimserp

  好了轻轻松松的就将excel中的数据插入数据库了,poi的测试也就到此结束!!我也可以给我朋友说,no problem,

  你需要的很快竟能完成,:)

  看看还需要足作些什么  哦!!  后面几天将把它移植到struts框架下,将用eclipse 2.1 版本+easystruts 快速开发 

    

草拟开发小组章程和与副组长、程序设计队队

    前天,经过数天的思考和一下午的编写,终于完成了小组章程的草案和小组成员名单的编制。

    前天晚上,我按给网友们的承诺,提交了章程草案,发送了开发小组2004.11.18-2004.12.18成员名单。学习日记开发小组总算是成立了。共有30几个网友加入。

    昨天晚上,我给副组长和程序设计队队长发了一封商量当前工作的邮件,这两天是周末,不知他们收到没有。

    今天,有朋友建议用qq群联系大家,我还没有用过qq群,应该学习一下。

    还有不少成员没有读章程草案,并且还没有人对章程草案提出意见和建议。章程草案计划有2个月试行期,但应该充分使大家加入到章程的修改和定稿中来,这样,章程才能体现大家的意愿,才可能得到有效的贯彻和实施。

    今天晚上,我就把章程草案和开发小组成员名单发到各成员的邮箱中去,提请大家审定。

    今天我才觉得工作有点失误,应该让大家统一都提供qq作为即时通讯。我们的主要交流平台是www.learndiary.com,但是,用即时通讯工具快速交流是不可缺少的。今天晚上的这封信也让没有提供qq号的朋友补充一下qq号,为建立qq群作好准备。

学习日记开发小组需求分析设计区

希望项目组各成员把在学习日记项目需求分析设计阶段遇到的技术性问题和解决方案,和有关的学习资料、学习心得共享出来。

请踊跃发帖!

1、在这个目标下的评论中用于成员间的日常交流;

2、在这个目标下的日记中记录您个人的相关日记。

学习日记开发小组成员工作日记

这个目标是用于学习日记开发小组所有成员记录自己参与学习日记开发的非技术类日记,

比如工作进度、工作计划、工作心得等等。

我们用这个目标来保证成员之间的工作协调,并为抵御开发小组成员的分散性和流动性起到一定作用。

使用约定:

1、在这个目标下的评论中用于成员间的日常交流;

2、在这个目标下的日记中记录您个人的相关日记。

咪妹摔倒了,健康状况基本上正常了

    昨天,我母亲带咪妹玩。咪妹不小心摔倒了,鼻子、下巴、上嘴皮有点擦伤。估计不会有什么影响。

    老婆今天问我是怎么一回事。我说是我带咪妹时摔倒的。

    为了保护大家的和睦,我觉得人有时需要说点善意的谎言。

    经过20来天的折腾,咪妹的健康状况基本上正常了。