中文字幕亚洲综合久久菠萝蜜 ,亚洲日韩中文字幕天堂不卡 ,亚洲福利精品电影在线观看http://www.tkk7.com/alexwan/category/32009.htmlLet life be beautiful like summer flowers and death like autumn leaves.zh-cnSat, 07 Jun 2008 03:03:23 GMTSat, 07 Jun 2008 03:03:23 GMT60tomcat5下jsp出現getOutputStream() has already been called for this response異常的原因和解決方法http://www.tkk7.com/alexwan/articles/206480.html萬洪泉萬洪泉Sat, 07 Jun 2008 02:27:00 GMThttp://www.tkk7.com/alexwan/articles/206480.htmlhttp://www.tkk7.com/alexwan/comments/206480.htmlhttp://www.tkk7.com/alexwan/articles/206480.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206480.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206480.html在tomcat5下jsp中出現此錯誤一般都是在jsp中使用了輸出流(如輸出圖片驗證碼,文件下載等),
沒有妥善處理好的原因。
具體的原因就是
在tomcat中jsp編譯成servlet之后在函數_jspService(HttpServletRequest request, HttpServletResponse response)的最后
有一段這樣的代碼
finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
這里是在釋放在jsp中使用的對象,會調用response.getWriter(),因為這個方法是和
response.getOutputStream()相沖突的!所以會出現以上這個異常。

然后當然是要提出解決的辦法,其實挺簡單的(并不是和某些朋友說的那樣--
將jsp內的所有空格和回車符號所有都刪除掉),

在使用完輸出流以后調用以下兩行代碼即可:
out.clear();
out = pageContext.pushBody();

最后這里是一個輸出彩色驗證碼例子(這樣的例子幾乎隨處可見)
imag.jsp

<%@ page  import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%@ page import="java.io.OutputStream" %>
<%!
Color getRandColor(int fc,int bc){
Random random = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
%>
<%
try{
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
OutputStream os=response.getOutputStream();
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);

g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.setColor(getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}
String sRand="";
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(rand,13*i+6,16);
}
session.setAttribute("rand",sRand);
g.dispose();

ImageIO.write(image, "JPEG",os);
os.flush();
os.close();
os=null;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
catch(IllegalStateException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}%>


如有不足之處,歡迎斧正! 



萬洪泉 2008-06-07 10:27 發表評論
]]>
jxl讀寫excel的簡單例子http://www.tkk7.com/alexwan/articles/206479.html萬洪泉萬洪泉Sat, 07 Jun 2008 02:26:00 GMThttp://www.tkk7.com/alexwan/articles/206479.htmlhttp://www.tkk7.com/alexwan/comments/206479.htmlhttp://www.tkk7.com/alexwan/articles/206479.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206479.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206479.html
import java.io.File;
import java.io.FileOutputStream;

import jxl.Workbook;
import jxl.format.BorderLineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class jxltest
{
public static void main(String [] args)
{
String templatePath 
= "c:\\template.xls";//模板文件名
String outFileStr = "c:\\test.xls";//測試文件名(輸出文件)
try
{
//創建小字體:Arial,大小為8號,非粗體,非斜體
WritableFont wf = new WritableFont(WritableFont.ARIAL, 8,WritableFont.NO_BOLD, false);
//字體顏色為紅色
wf.setColour(jxl.format.Colour.RED);
//創建大字體:Arial,大小為18號,粗體,非斜體
WritableFont Bwf = new WritableFont(WritableFont.ARIAL, 18,WritableFont.NO_BOLD, false);
Bwf.setColour(jxl.format.Colour.RED);
//創建單元格格式:設置水平對齊為向右對齊
jxl.write.WritableCellFormat RwcfF = new jxl.write.WritableCellFormat(wf);
RwcfF.setAlignment(jxl.write.Alignment.RIGHT);
//創建單元格格式:設置水平對齊為向左對齊
jxl.write.WritableCellFormat LwcfF = new jxl.write.WritableCellFormat(wf);
LwcfF.setAlignment(jxl.write.Alignment.LEFT);
//創建單元格格式:設置水平對齊為居中對齊
jxl.write.WritableCellFormat CwcfF = new jxl.write.WritableCellFormat(wf);
CwcfF.setAlignment(jxl.write.Alignment.CENTRE);
jxl.write.WritableCellFormat CBwcfF 
= new jxl.write.WritableCellFormat(Bwf);
CBwcfF.setAlignment(jxl.write.Alignment.CENTRE);
//設置垂直對齊為居中對齊
CBwcfF.setVerticalAlignment(VerticalAlignment.CENTRE);
//設置頂部邊框線為實線(默認是黑色--也可以設置其他顏色)
CBwcfF.setBorder(jxl.format.Border.TOP, BorderLineStyle.MEDIUM);
//設置右邊框線為實線
CBwcfF.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.MEDIUM);
//設置頂部框線為實線
CBwcfF.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.MEDIUM);
jxl.write.WritableCellFormat CMwcfF 
= new jxl.write.WritableCellFormat(wf);
CMwcfF.setAlignment(jxl.write.Alignment.LEFT);
//設置垂直對齊為向上對齊
CMwcfF.setVerticalAlignment(VerticalAlignment.TOP);
CMwcfF.setWrap(
true);
File tFile 
= new File(templatePath);//創建模板文件對象
File outFile = new File(outFileStr);//創建輸出文件對象
//創建文件輸出流對象
FileOutputStream os = new FileOutputStream(outFile);
//模板工作簿對象
Workbook tBook = Workbook.getWorkbook(tFile);
//輸出工作簿對象
WritableWorkbook wbook = Workbook.createWorkbook(os, tBook);
//在坐標為(0,0)的單元格寫入"測試"字符串使用8號紅色小字體,向右對齊
wsheet.addCell(new Label(00"test", RwcfF));
//在坐標為(1,1)的單元格寫入"test"字符串使用8號紅色小字體,向左對齊
wsheet.addCell(new Label(11"test", LwcfF));
//在坐標為(2,2)的單元格寫入"測試test"字符串使用8號紅色小字體,居中對齊
wsheet.addCell(new Label(2,2"測試test", CMwcfF));
//在坐標為(3,3)的單元格寫入2.00使用18號紅色大字體,居中對齊
wsheet.addCell(new Number(23142.00, CBwcfF));
//寫入
wbook.write();
wbook.close();
tBook.close();
//關閉文件輸出流
os.close();     
}

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


}


}
 



萬洪泉 2008-06-07 10:26 發表評論
]]>
常用的與時間戳(Timestamp)相關的函數總結TimestampUtil http://www.tkk7.com/alexwan/articles/206477.html萬洪泉萬洪泉Sat, 07 Jun 2008 02:24:00 GMThttp://www.tkk7.com/alexwan/articles/206477.htmlhttp://www.tkk7.com/alexwan/comments/206477.htmlhttp://www.tkk7.com/alexwan/articles/206477.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206477.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206477.html閱讀全文

萬洪泉 2008-06-07 10:24 發表評論
]]>
常用的與字符串相關的函數總結StringUtil http://www.tkk7.com/alexwan/articles/206476.html萬洪泉萬洪泉Sat, 07 Jun 2008 02:23:00 GMThttp://www.tkk7.com/alexwan/articles/206476.htmlhttp://www.tkk7.com/alexwan/comments/206476.htmlhttp://www.tkk7.com/alexwan/articles/206476.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206476.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206476.html閱讀全文

萬洪泉 2008-06-07 10:23 發表評論
]]>
tomcat數據源讀取的簡單例子 http://www.tkk7.com/alexwan/articles/206475.html萬洪泉萬洪泉Sat, 07 Jun 2008 02:21:00 GMThttp://www.tkk7.com/alexwan/articles/206475.htmlhttp://www.tkk7.com/alexwan/comments/206475.htmlhttp://www.tkk7.com/alexwan/articles/206475.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206475.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206475.html應朋友的要求寫下這篇文章,實現一個簡單的例子,用于讀取tomcat數據源

BaseDAO.java

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


public class BaseDAO
{
 
private static DataSource pool = null;
 
private static Context env = null;
 
//private Connection conn = null;
 protected String tableName="";
 
public BaseDAO() throws AppException//構造
 {
  
if (pool != nullreturn;
  
  
try
  
{
   env 
= (Context) new InitialContext().lookup("java:comp/env");
   pool 
= (DataSource)env.lookup("jdbc/" + "appid");//數據源id
  }

  
catch(NamingException ne) 
  
{
   env 
= null;
   pool 
= null;
   System.out.println(ne.getMessage());
   
throw new AppException(ne.getMessage());
  }

 }

 
 
public Connection getConn() throws AppException//獲取連接
 {
  
try
  
{
   
if (pool == null)
    
throw new AppException("Data source invalid!");
   
else
    
return pool.getConnection();
  }

  
catch(SQLException e) 
  
{
   
throw new AppException(e.getMessage());
  }

 }

 
 
public void closeConn(Connection conn)//關閉連接
 {
  
try
  
{
   
if (conn != null) conn.close();
  }

  
catch (Exception e)
  
{
  }

 }

}

另外AppException的實現如下:
AppException.java

import java.lang.Exception;

public class AppException extends Exception
{
 
/**
  * 
  
*/

 
private static final long serialVersionUID = 1L;

 
public AppException(Exception exc)
 
{
  
super(exc.getCause());
 }

 
 
public AppException(String errorMessage)
 
{
  
super(errorMessage);
 }

}


 

其實這一種方式也不是最好的方式,而且依賴tomcat的數據源,開啟了連接后一定要記得關閉連接,這樣管理起來容易出錯,建議可以是使用ibatis替代



萬洪泉 2008-06-07 10:21 發表評論
]]>
java中簡單的翻頁功能的實現(PageManager) http://www.tkk7.com/alexwan/articles/206474.html萬洪泉萬洪泉Sat, 07 Jun 2008 02:19:00 GMThttp://www.tkk7.com/alexwan/articles/206474.htmlhttp://www.tkk7.com/alexwan/comments/206474.htmlhttp://www.tkk7.com/alexwan/articles/206474.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206474.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206474.htmlpackage util;
import java.util.List;

public class PageManager
{
    private List allRecords = null;//collection儲存同一類型的對象的集合
    private int currentPage = 0;//當前頁碼
    private int totalPage = 0;//總頁數
    private int recordPerPage = -1;//每頁的對象數
    private int totalCount=0;//總的對象數
 //初始化
 public PageManager(List allRecords, int recordPerPage)
    {
        if (allRecords == null || recordPerPage < 1) return;

        this.allRecords = allRecords;
        this.recordPerPage = recordPerPage;
        this.totalCount=allRecords.size();
        if (allRecords.size() % recordPerPage == 0)
            this.totalPage = allRecords.size() / recordPerPage;
        else
            this.totalPage = allRecords.size() / recordPerPage + 1;
        this.currentPage = 0;
    }
    //獲取所有對象集合
    public List getAllRecords()
    {
     return this.allRecords;
    }
 //獲取當前頁的的對象集合
    public List getCurrentPage()
    {
     return getPage(currentPage);
    }
    //根據序號獲取該對象所在的頁的對象集合
    public List getThePage(int recordno)
    {
     if (this.allRecords == null || this.allRecords.size() == 0)
        {
            this.currentPage = 0;
            return null;
        }
        int pageNo=1;
        if (recordno < 1) pageNo = 1;
       
        else if (recordno > this.allRecords.size())
         pageNo = this.totalPage;
        else
        {
         pageNo=recordno/this.recordPerPage+1;
        }
        this.currentPage = pageNo;
       
        int pageStart = (pageNo - 1) * this.recordPerPage;
        int pageEnd = pageStart + this.recordPerPage - 1;
        if (pageEnd > this.allRecords.size() - 1) pageEnd = this.allRecords.size() - 1;
       
        List result =this.allRecords.subList(pageStart, pageEnd+1);       
        return result;
    }
   //根據頁碼獲取改頁的對象集合
    public List getPage(int pageNo)
    {
        if (this.allRecords == null || this.allRecords.size() == 0)
        {
            this.currentPage = 0;
            return null;
        }
       
        if (pageNo < 1) pageNo = 1;
        if (pageNo > this.totalPage) pageNo = this.totalPage;
        this.currentPage = pageNo;
       
        int pageStart = (pageNo - 1) * this.recordPerPage;
        int pageEnd = pageStart + this.recordPerPage - 1;
        if (pageEnd > this.allRecords.size() - 1) pageEnd = this.allRecords.size() - 1;
        List result =this.allRecords.subList(pageStart, pageEnd+1);
        return result;
    }
    //獲取下一頁的對象集合
    public List getNextPage()
    {
        return getPage(this.currentPage + 1);
    }
     //獲取上一頁的對象集合
    public List getPreviousPage()
    {
        return getPage(this.currentPage - 1);
    }
   //獲取第一頁的對象集合 
    public List getFirstPage()
    {
        return getPage(1);
    }
  //獲取最后一頁的對象集合
    public List getLastPage()
    {
        return getPage(this.totalPage);
    }
   //獲取總頁數
 public int getTotalPage() {
  return totalPage;
 }
 //獲取當前頁碼 
 public int getCurrentPageCount()
 {
  return this.currentPage;
 }
 //獲取對象總數
 public int getTotalCount() {
  return totalCount;
 }


}



萬洪泉 2008-06-07 10:19 發表評論
]]>
在appfuse構建的項目中集成velocity的步驟和碰到的問題http://www.tkk7.com/alexwan/articles/206470.html萬洪泉萬洪泉Sat, 07 Jun 2008 01:54:00 GMThttp://www.tkk7.com/alexwan/articles/206470.htmlhttp://www.tkk7.com/alexwan/comments/206470.htmlhttp://www.tkk7.com/alexwan/articles/206470.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206470.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206470.html使用Velocity無非也就是為了能夠真正的實現mvc分層,使得各個團隊成員(美工,程序員)可以各盡所長。

在appfuse構建的項目中集成velocity的步驟和碰到的問題 :

1:修改web.xml使得項目支持velocity

(1)定義名為velocity的servlet:

<servlet>
        
<servlet-name>velocity</servlet-name>
        
<servlet-class>
            org.apache.velocity.tools.view.servlet.VelocityViewServlet
        
</servlet-class>
        
<init-param>
            
<param-name>org.apache.velocity.toolbox</param-name>
            
<param-value>/WEB-INF/toolbox.xml</param-value>
        
</init-param>
        
<init-param>
            
<param-name>org.apache.velocity.properties</param-name>
            
<param-value>
                /WEB-INF/classes/velocity.properties
            
</param-value>
        
</init-param>
        
<load-on-startup>10</load-on-startup>
    
</servlet>

(2)定義對應velocity的servlet-mapping:

  <servlet-mapping>
        
<servlet-name>velocity</servlet-name>
        
<url-pattern>*.vm</url-pattern>
    
</servlet-mapping>

(3)將velocity納入到編碼過濾的filter(一般都已經定義經典SetCharacterEncoding):

 <filter-mapping>
        
<filter-name>SetCharacterEncoding</filter-name>
        
<url-pattern>*.vm</url-pattern>
    
</filter-mapping>
2:在項目的web/WEB-INF文件夾中創建并編輯文件toolbox.xml,通常的內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<toolbox>
  
<tool>
     
<key>link</key>
     
<scope>request</scope>
     
<class>org.apache.velocity.tools.struts.StrutsLinkTool</class>
  
</tool>
  
<tool>
     
<key>text</key>
     
<scope>request</scope>
     
<class>org.apache.velocity.tools.struts.MessageTool</class>
  
</tool>
  
<tool>
     
<key>errors</key>
     
<scope>request</scope>
     
<class>org.apache.velocity.tools.struts.ErrorsTool</class>
  
</tool>
  
<tool>
     
<key>form</key>
     
<scope>request</scope>
     
<class>org.apache.velocity.tools.struts.FormTool</class>
  
</tool>
  
<tool>
     
<key>tiles</key>
     
<scope>request</scope>
     
<class>org.apache.velocity.tools.struts.TilesTool</class>
  
</tool>
  
<tool>
     
<key>validator</key>
     
<scope>request</scope>
     
<class>org.apache.velocity.tools.struts.ValidatorTool</class>
  
</tool>
</toolbox>

3:在項目的build/web/classes文件夾中創建并編輯文件velocity.properties,通常的內容:
input.encoding = UTF-8
#out.encoding = UTF-8
default.contentType=text/html; charset=UTF-8

---以上三步其實就是普通java web項目集成velocity的必須要做的工作了。
---下面是使用appfuse中的appgen生成velocity代碼的要做的工作,這里只做了從table出發的生成過程。

4:在項目中extras/appgen/src中創建模板,這里假設創建的兩個文件是List_vm.xdt和Form_vm.xdt
模板的具體內容就要結合xdoclet,velocity和html來編寫,不是一個簡單的工作!

5:編輯extras/appgen下的build.xml文件,使得在使用ant install-detailed的時候能生成數據表對應的vm文件.

(1):在名為gen的target中添加template,原文件有以下的代碼:


<!-- Form JSP -->
            
<template templateFile="${template.dir}/Form_jsp.xdt"
                      acceptAbstractClasses
="false"
                      prefixWithPackageStructure
="false"
                      destinationFile
="${gen.dir}/web/pages/{0}FormTemp.jsp"/>
            
<!-- List JSP -->
            
<template templateFile="${template.dir}/List_jsp.xdt"
                      acceptAbstractClasses
="false"
                      prefixWithPackageStructure
="false"
                      destinationFile
="${gen.dir}/web/pages/{0}ListTemp.jsp"/>
我們要在這個后面添加以下代碼(如果不使用jsp作為view層可以使用替換的方式把原文件的這部分內容處理掉):
<!-- Form VM -->
            
<template templateFile="${template.dir}/Form_vm.xdt"
              acceptAbstractClasses
="false"
              prefixWithPackageStructure
="false"
              destinationFile
="${gen.dir}/web/vms/{0}FormTemp.vm"/>
            
<!-- List VM -->
               
<template templateFile="${template.dir}/List_VM.xdt"
              acceptAbstractClasses
="false"
              prefixWithPackageStructure
="false"
              destinationFile
="${gen.dir}/web/vms/{0}ListTemp.vm"/>

這里,templateFile里指定模板文件,destinationFile指定生成的臨時文件。

(2):在名字同樣為gen的target中添加move任務,原文件中有以下代碼:


<!-- Make first character of JSP filenames lowercase -->
        
<move file="${build.dir}/${gen.dir}/web/pages/${model.name}ListTemp.jsp"
            tofile
="${build.dir}/${gen.dir}/web/pages/${app.module.slash.after}${model.name.lowercase}List.jsp"/>
        
<move file="${build.dir}/${gen.dir}/web/pages/${model.name}FormTemp.jsp"
            tofile
="${build.dir}/${gen.dir}/web/pages/${app.module.slash.after}${model.name.lowercase}Form.jsp"/>

我們要在這個后面添加以下代碼(如果不使用jsp作為view層可以使用替換的方式把原文件的這部分內容處理掉):
<!-- Make first character of Velocity filenames lowercase -->
        
<move file="${build.dir}/${gen.dir}/web/vms/${model.name}ListTemp.vm"
            tofile
="${build.dir}/${gen.dir}/web/vms/${app.module.slash.after}${model.name.lowercase}List.vm"/>
        
<move file="${build.dir}/${gen.dir}/web/vms/${model.name}FormTemp.vm"
            tofile
="${build.dir}/${gen.dir}/web/vms/${app.module.slash.after}${model.name.lowercase}Form.vm"/>

這樣生成的臨時文件就會被重命名(有點懷疑這樣做的必要性,暫且先這樣做吧)。

(3):在名為merge-common的target中添加copy任務,原文件中有如下代碼


  <!-- copy jsp files -->
        
<echo>Copying all web files into main project, overwrite="${overwrite}"</echo>
        
<copy todir="../../web/pages">
            
<fileset dir="${generated.dir}/web/pages" includes="**/${model.name.lowercase}*.jsp"/>
        
</copy>

我們要在這個后面添加以下代碼(如果不使用jsp作為view層可以使用替換的方式把原文件的這部分內容處理掉):
 <!-- copy velocity files -->
        
<echo>Copying all velocity files into main project, overwrite="${overwrite}"</echo>
        
<copy todir="../../web/vms">
            
<fileset dir="${generated.dir}/web/vms" includes="**/${model.name.lowercase}*.vm"/>
        
</copy>

這樣在使用ant install-detailed命令時就會把生成的文件復制到項目的web/vms文件夾下了。

7:修改項目的根目錄下的build.xml:

(1)修改名為copy-web-files的target,使得運行ant deploy時可以將vm文件復制到部署項目的WEB-INFO文件夾下(放在WEB-INF下是為了防止直接訪問 )。
參考的源代碼:


 <!-- Copy JSP Pages under WEB-INF/pages -->
        
<copy todir="${webapp.target}/WEB-INF">
            
<fileset dir="${basedir}/web">
                
<include name="pages/**/*.jsp"/>
            
</fileset>
            
<fileset dir="${struts.dir}" includes="*.xml"/>
            
<fileset dir="${basedir}/web/WEB-INF" includes="**/*-resources.xml"/>
            
<filterset refid="db.variables"/>
        
</copy>

可以在這個任務后面添加一個任務:
<fileset dir="${basedir}/web">
                
<include name="vms/**/*.vm"/>
            
</fileset>

另外,如果不再使用jsp做為view層可以把匹配jsp的fileset節點去掉,這樣就不會復制多余的文件到部署的項目中了。

(2)同名的target 中修改另外一個copy任務(順數第二個),源代碼:

 <copy todir="${webapp.target}" includeEmptyDirs="no">
            
<fileset dir="${basedir}/web">
                
<include name="**"/>
                
<exclude name="pages/**"/>
                
<exclude name="**/classes/**"/>
                
<exclude name="**/*-resources.xml"/>
            
</fileset>
        
</copy>

在fileset中添加一個節點:
<exclude name="vms/**"/>

這樣就不會把vms文件夾下的文件當成是普通文件那樣復制了

8:在struts-config.xml修改forwards,使得它們指向特定的vm。

ps:基本上就是這么多的步驟,遺漏的地方,歡迎補充!



萬洪泉 2008-06-07 09:54 發表評論
]]>
appfuse構建項目的常見問題 http://www.tkk7.com/alexwan/articles/206468.html萬洪泉萬洪泉Sat, 07 Jun 2008 01:44:00 GMThttp://www.tkk7.com/alexwan/articles/206468.htmlhttp://www.tkk7.com/alexwan/comments/206468.htmlhttp://www.tkk7.com/alexwan/articles/206468.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206468.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206468.html 1. 如何在翻頁的時候才讀取下面的數據?
2. 怎樣對使用同一個FormBean的多個Form進行客戶端校驗?
3. 怎樣優化Hibernate的效率?《Hibernate In Action》中提供了多種策略,有些時候應該使用lazy,有些時候應該使用outer-join。
4. 在什么時機生成導出文件?目前我是在查詢的Action中同時生成了導出文件,否則,到了下一頁,我就不知道查詢條件了,當然,如果把拼裝后的HQL存儲在Session或者Hidden中也可以解決這個問題,但是這樣就破壞了DAO的封裝,要把DAO封裝后的HQL發送給Action,然后發送的到Web界面層,所以目前我還在猶豫生成導出文件的時機選擇在哪里?
5. 什么時候應該自己獲取數據庫連接,執行native SQL?具體需要注意些什么?
6. SiteMesh的模板優化?
7. DisplayTag的底層實現?

8.如何使用velocity作為view層?

這個框架的優點是:如果熟悉了開發流程,可以大幅度的提高開發速度,如果業務不是很復雜,使用AppGen可以生成60%左右的代碼,而且程序可維護性好,因為作者使用了多個設計模式對各個層面進行了封裝,所以不同的模塊代碼風格出奇的一致,有利于開發人員快速上手,也有利于接收其他開發人員遺留的代碼。



在appgen中修改build.xml的target可以控制生成那些代碼,另外還可以修改模板,使得appgen生成更接近自己需要的代碼。要利用好這些優點的前提是,程序員本身對ant要有相當的了解。



萬洪泉 2008-06-07 09:44 發表評論
]]>
appfuse下使用ibatis的一般步驟和若干問題http://www.tkk7.com/alexwan/articles/206466.html萬洪泉萬洪泉Sat, 07 Jun 2008 01:41:00 GMThttp://www.tkk7.com/alexwan/articles/206466.htmlhttp://www.tkk7.com/alexwan/comments/206466.htmlhttp://www.tkk7.com/alexwan/articles/206466.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206466.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206466.html 1:在生成的項目的extras/ibatis下運行ant install
刷新項目,出現兩個錯誤:
Project ngucs is missing required library: 'lib/ibatis-2.1.7/jta.jar'
The project cannot be built until build path errors are resolved
兩種方法解決可以這個問題:
(1)打開.classpath文件,將下面這一行刪除(因為在hibernate的配置中已經引用了jta.jar)
<classpathentry kind="lib" path="lib/ibatis-2.1.7/jta.jar"/>
(2)將lib/hibernate-3.1.3/lib/jta.jar拷貝到lib/ibatis-2.1.7/,刷新項目。
2:如果不使用hibernate相關的操作,那么將和hibernate相關的文件(包括配置文件)和包刪除,以防發生混淆
3:修改在生成的項目extras/appgen文件的build.xml
<target name="merge-config" depends="merge-tests,merge-menu,merge-hibernate,merge-ibatis">
中的“merge-hibernate,”去掉,這樣在appgen下運行ant install-detailed的時候就不會生成hibernate相關的文件了!
4:生成文件不一定都能通過編譯,原因有很多種,常見的原因有:
(1)數據表設計時對主鍵的類型的錯誤設計,通常是太短了,建議主鍵都使用bigserial類型,如果使用serial,在生成的文件中多處會出現對int類型一些操作!使用bigserial對應生成的類型是Integer這樣就不會有錯了!--對應這種錯誤,如果不能修改數據的設計的話就只好修改代碼咯!快捷的方法是將model中主鍵對應的成員變量的類型改成Integer,在其他地方(xml,dao,servic,action)對這個成員變量的引用(一般通過取值函數)也做相應的類型修改就可以了。
5:修改完和主鍵相關的地方后,發現還有幾個和form相關的錯誤,這是因為相應的form還沒有生成,回到項目的根目錄,使用ant deploy命令就會生成了.
6:關于insert中的selectKey,pgsql中應該是這樣放到insert sql語句后面,使用的函數應該是currval('tablename_id_seq')
7:可以在appgen中修改相應的模板(xdt文件--一般在生成的項目extras/appgen/src中),使得appgen生成的代碼更接近自己的需要的代碼,這樣就可以減少生成代碼后的修改工作。


萬洪泉 2008-06-07 09:41 發表評論
]]>
將appfuse應用于pgsql的時候碰到的若干問題http://www.tkk7.com/alexwan/articles/appfuse_pgsql.html萬洪泉萬洪泉Sat, 07 Jun 2008 01:39:00 GMThttp://www.tkk7.com/alexwan/articles/appfuse_pgsql.htmlhttp://www.tkk7.com/alexwan/comments/206465.htmlhttp://www.tkk7.com/alexwan/articles/appfuse_pgsql.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206465.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206465.html http://www.ibm.com/developerworks/cn/java/j-lo-appfuse/index.html
將appfuse應用于pgsql的時候碰到的若干問題:

ant new之后在用eclipse打開項目會有五個錯誤--原因是.classpath文件里面聲明了五個src類型的文件夾

碰到的數據庫相關問題----原因在于使用的是pgsql
在建立的項目文件夾里ant setup的時候會出錯,原因在于數據庫的設置錯誤:
解決的方法:
將build.properties里面關于數據庫設置的內容釋放出來,并根據自己的需要修改各個key對應的value
另外:如果還引用database.name還要添加database.name=postgres這樣一個屬性,否則會報錯說database.name不存在
運行 ant test-all
會出現另外一個錯誤:role "test" doesn't exist.
解決的方法:
將properties.xml中的

<property name="database.username" value="test"/>
<property name="database.password" value="test"/>
改成
<property name="database.username" value="postgres"/>
<property name="database.password" value=""/>

再運行 ant test-all
 在開啟tomcat的時候會出錯(如果tomcat設置和默認的不同)
默認的定義在properties.xml的這幾項設置

<property name="tomcat.server" value="localhost"/>
    
<property name="tomcat.manager.url" value="http://${tomcat.server}:${http.port}/manager"/>
    
<property name="tomcat.username" value="admin"/>
    
<property name="tomcat.password" value="admin"/>

只要將這幾項改成和真實的tomcat設置,下面是我的例子:
 <property name="tomcat.server" value="localhost"/>
 
<property name="tomcat.manager.url" value="http://${tomcat.server}:8686/manager"/>
 
<property name="tomcat.username" value="admin"/>
 
<property name="tomcat.password" value=""/>
再次運行ant test-all,到最后還是會有錯,這是因為國際化文件的亂碼問題(中文),而且這個亂碼不是所有字符都亂碼
而是,只有個別文字亂碼--當然具體原因我也不知道,能做的就是按照上下文進行編輯了!
資源文件所在位置:web/WEB-INF/classes
在這里我使用的Properties Editor,比較方便(我可以提供一份已修改好的資源作為參考)!

<其實這里如果用ant deploy命令是可以啟動項目的啦,只是登陸頁面測試的結果和期待的結果用一樣>

另外切換到英文的時候也會找不到國際化的內容,反而裝載了中文的資源文件的內容;這里是因為
ApplicationResources_en.properties文件是空的,估計原因是在裝載資源文件的順序上的原因吧,
我發現ApplicationResources.properties并不是空的,原則上是不會去裝載中文的資源文件啊。
解決這個問題只要將ApplicationResources.properties的內容拷貝到ApplicationResources_en.properties
就可以了(這里有一種治標不治本的味道)。

在初生成版本的用戶列表里面也又亂碼的問題(中文的情況下),在表頭和表尾的地方!
這樣編輯另外一個文件:
displaytag_zh_cn.properties--路徑為web/WEB-INF/classes
切換到英文版的時候發現又裝載了中文的資源內容,檢查原來是缺失了這個文件:
displaytag_en.properties
創建一個文件并使用編輯之!
具體的內容可以參考

http://displaytag.sourceforge.net/configuration.html

現在在項目目錄下運行ant deploy然后訪問,就可以出現一個基本正常的期望站點了。

By the way:ant deploy命令有時候會出現tomcat使用cpu占用率非常高的現象(導致卡機),至少我自己就發生了幾次。:(

現在讓我們來嘗試一下新的工具:AppGen代碼生成:
創建數據表,生成代碼,關聯hibernate文件,這些都不累贅了,因為前面所說的入門文章里面都有說了,照做便是!
不過這里也出現了問題,在我們運行回到項目文件夾里ant deploy之后,去訪問剛生成的文件的添加頁面的時候,你會發現有問題。

No form found under 'mytablenameForm' in locale 'zh_CN'
解決這個問題有兩種方法:
(1)在build/yourapp/WEB-INF/pages/下找到你生成的文件中的form.jsp文件,去掉script標簽內的內容,并去除form的檢驗
(2)在build/yourapp/WEB-INF的validation.xml文件中加入你對應的那個form,當然這里需要至少檢查一個field!
選擇哪種方法依具體情況而定.

再運行ant deploy,在之前出錯的地方就不再出錯了!

關于新生成表的國際化:
AppGen生成代碼的時候只在 ApplicationResources.properties種添加了相關的元素
我們要做的工作就需要修改ApplicationResources_en.properties(直接拷貝)和
ApplicationResources_zh_CN.properties(拷貝并編輯)才能實現國際化

 


小小的總結一下:
Appfuse的優點:當然是快了,生成的代碼非常清晰,人工干預比較少,部署方便。

目前的現實:appfuse的模板(主要是在國際化方面)似乎本身還有有點問題,出現不少亂碼。

團隊的問題:使用ant,對程序員的要求比較高,特別是習慣了用可視化ide編程的程序員,對這種方式比較抵觸。

 

--后來我發現可以在AppFuse的目錄下(web/WEB_INF/classes)替換掉之前的原文件,在生成的件就不會亂碼了
哦啊啊啊啊--我打開解壓后appfuse一看,偶的神仙的,appfuse解壓之后就是一個eclipse項目----如果我之間去編輯解壓后的
appfuse,然后在用ant命令(或直接在eclipse用)生成項目,又會怎么樣呢?真又一種迫不及待要試一下的感覺! 



 



萬洪泉 2008-06-07 09:39 發表評論
]]>
appfuse中生成以S結尾的數據表對應的代碼出錯的解決方案 http://www.tkk7.com/alexwan/articles/appfuse.html萬洪泉萬洪泉Sat, 07 Jun 2008 01:28:00 GMThttp://www.tkk7.com/alexwan/articles/appfuse.htmlhttp://www.tkk7.com/alexwan/comments/206463.htmlhttp://www.tkk7.com/alexwan/articles/appfuse.html#Feedback0http://www.tkk7.com/alexwan/comments/commentRss/206463.htmlhttp://www.tkk7.com/alexwan/services/trackbacks/206463.html 在google搜索相關的信息,只找到這一篇文章是有用的,并給予我修改的思路。

http://jira.codehaus.org/browse/MIDDLEGEN-13?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel
The algorithm for creating singular versions of table names doesn't account for singular words that end in "s". For example, a table called MumbleFooStatus becomes MumbleFooStatu
Suggestion #1: in Util.singularise(), check for a vowel other than "e" before a final "s".

Suggestion #2: change the default behaviour to not singularise tablenames. I think it's bad form for a tool to change the names of my data objects without my consent.

Workarounds: specify table names in build.xml, or if you're using the hibernate plugin, fix the table names in the <dbname>-prefs.properties generated by the plugin and re-run middlegen.

第二點中提到改變middlegen的默認行為讓其不去單數化數據表名。

我們要做的有幾個步驟(粗略的看了middlegen源碼做的修改):
1:下載middlegen源碼,下載地址
http://sourceforge.net/project/downloading.php?group_id=36044&use_mirror=jaist&filename=middlegen-2.1-src.zip
2:解壓并編輯MiddlegenTask.java中的代碼

private static boolean _singularize = true;
改成
private static boolean _singularize = false;
3:重新編譯并打包成jar,在middlegen的根目錄下輸入命令行命令:ant jar即可
4:將新的middlegen-2.1.jar替換目標項目(已生成)中extras\middlegen\lib\middlegen-2.1的middlegen-2.1.jar
這樣,在生成以S結尾的數據表名對應的代碼就不會出錯了!
但是這樣做始終有不好的地方:在表示對象復數的地方就會出現不盡人意的代碼了,但是不管怎么樣,代碼還是生成出來了,后期的工作就可以依靠手動去修改。
所以還是盡量去遵循不以S結尾的單詞作為數據表名。 



萬洪泉 2008-06-07 09:28 發表評論
]]>
主站蜘蛛池模板: 91视频免费观看| 国产亚洲美女精品久久久2020 | 国产麻豆视频免费观看| 日本精品久久久久久久久免费| 亚洲国产精品综合久久2007| 亚洲av永久无码精品网站 | 2022免费国产精品福利在线| 亚洲AV无码无限在线观看不卡 | 免费看一区二区三区四区| 亚洲Av永久无码精品一区二区| 亚洲精品电影天堂网| 亚洲国产一成人久久精品| 亚洲精品无码av天堂| 四虎影永久在线高清免费| 成人免费毛片视频| 久久精品国产免费观看三人同眠| 可以免费观看的毛片| 九九热久久免费视频| 产传媒61国产免费| 色一情一乱一伦一视频免费看| 亚洲偷自拍另类图片二区| 亚洲免费在线视频播放| 亚洲精品视频专区| 亚洲伊人tv综合网色| 亚洲AV日韩AV永久无码久久| 亚洲人成精品久久久久| 中文字幕在线亚洲精品| 国产亚洲?V无码?V男人的天堂 | 亚洲国产美女视频| 亚洲成无码人在线观看| 亚洲影视一区二区| 亚洲男人天堂影院| 亚洲人成网站在线观看播放青青| 亚洲激情校园春色| 亚洲依依成人精品| avtt天堂网手机版亚洲| 亚洲一区二区三区高清不卡 | 国产美女无遮挡免费网站| 永久免费毛片手机版在线看| 日本一道综合久久aⅴ免费| 国产极品粉嫩泬免费观看|