
工程目錄
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>android</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 第一 這個(gè)過濾器與Struts的核心過濾器協(xié)同工作,以便更容易與sitemesh整合 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<!-- 第二 sitemesh的過濾器,同時(shí)也整合了Freemarker -->
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
</filter>
<!-- 第三 struts2過濾器 -->
<filter>
<filter-name>struts2Filter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
使FreeMarker模塊能夠使用strut2標(biāo)簽,使用方式:<#assign
s=JspTaglibs["/WEB-INF/struts-tags.tld"] />
-->
<servlet>
<servlet-name>JspSupportservlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.convention.default.parent.package" value="crud-default" />
<constant name="struts.convention.package.locators" value="action" />
<constant name="struts.convention.package.locators.basePackage" value="org.david.android" />
<constant name="struts.convention.result.path" value="/WEB-INF/web" />
<!-- 用于CRUD Action的parent package -->
<package name="crud-default" extends="convention-default">
<!-- 基于paramsPrepareParamsStack,
增加store interceptor保證actionMessage在redirect后不會(huì)丟失 -->
<interceptors>
<interceptor-stack name="crudStack">
<interceptor-ref name="store">
<param name="operationMode">AUTOMATIC</param>
</interceptor-ref>
<interceptor-ref name="paramsPrepareParamsStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="crudStack" />
</package>
<!--
使用Convention插件,實(shí)現(xiàn)約定大于配置的零配置文件風(fēng)格.
特殊的Result路徑在Action類中使用@Result設(shè)定.
-->
</struts>
decorators.xml
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/decorators">
<decorator name="main" page="main.ftl">
<pattern>/*</pattern>
</decorator>
</decorators>
HelloWorldAction.java
package org.david.android.action.user;
public class HelloWorldAction {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String execute(){
this.message = "ITdavid";
return "success";
}
}
main.ftl
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>${title}</title>
</head>
<body>
<div>
hello
${body}
</body>
</html>
hello-world.ftl
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="layout" content="main"/>
<title>Insert title here</title>
</head>
<body>
Hello ${message!}
</body>
</html>
posted @
2009-11-29 17:05 大衛(wèi) 閱讀(3294) |
評(píng)論 (4) |
編輯 收藏
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>fmtest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/service-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<display-name>Stripes Filter</display-name>
<filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
<init-param>
<param-name>ActionResolver.Packages</param-name>
<param-value>net.sourceforge.stripes.examples</param-value>
</init-param>
<init-param>
<param-name>Interceptor.Classes</param-name>
<param-value>net.sourceforge.stripes.integration.spring.SpringInterceptor</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>StripesFilter</filter-name>
<servlet-name>StripesDispatcher</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>StripesDispatcher</servlet-name>
<servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>StripesDispatcher</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Freemarker</servlet-name>
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>template_update_delay</param-name>
<param-value>0</param-value> <!-- 0 is for dev only! Use higher value otherwise. -->
</init-param>
<init-param>
<param-name>DefaultEncoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
</web-app>
posted @
2009-11-25 15:45 大衛(wèi) 閱讀(1756) |
評(píng)論 (2) |
編輯 收藏
解決FreeMarker中文亂碼問題。
在web.xml中配置如下:
<servlet>
<servlet-name>Freemarker</servlet-name>
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>template_update_delay</param-name>
<param-value>3600</param-value> <!-- 0 值僅用于開發(fā)環(huán)境,生產(chǎn)環(huán)境請(qǐng)?jiān)O(shè)置為3600或者更大。 -->
</init-param>
<init-param>
<param-name>DefaultEncoding</param-name> <!-- 解決中文編碼問題 -->
<param-value>utf-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
--------------------
PES準(zhǔn)高手
posted @
2009-11-25 15:02 大衛(wèi) 閱讀(5067) |
評(píng)論 (1) |
編輯 收藏
RT
太保守會(huì)影響效率,當(dāng)某些代碼邏輯是認(rèn)為可控制時(shí),不用保守。
posted @
2009-09-28 10:08 大衛(wèi) 閱讀(429) |
評(píng)論 (0) |
編輯 收藏
關(guān)于類的劃分,上層應(yīng)該按業(yè)務(wù)領(lǐng)域含義劃分,下層應(yīng)該按實(shí)現(xiàn)細(xì)節(jié)劃分。
posted @
2009-09-27 12:10 大衛(wèi) 閱讀(414) |
評(píng)論 (0) |
編輯 收藏
其實(shí)很簡(jiǎn)單,就把標(biāo)記@Id放在主鍵(非自增)上就OK了。
posted @
2009-02-25 14:12 大衛(wèi) 閱讀(2555) |
評(píng)論 (0) |
編輯 收藏
摘要: 在設(shè)計(jì)數(shù)據(jù)庫(kù)表的時(shí)候,往往會(huì)設(shè)計(jì)出帶有復(fù)合主鍵的表,即表的記錄由多個(gè)字段聯(lián)合標(biāo)識(shí),如:
表
CREATE TABLE TB_HOUR_DATA
(
STAT_DATE DATE &...
閱讀全文
posted @
2009-02-25 14:10 大衛(wèi) 閱讀(3005) |
評(píng)論 (2) |
編輯 收藏
如何調(diào)用執(zhí)行iframe中的方法?如下:
document.getElementById("iframeId").contentWindow.functionName();
posted @
2008-10-07 14:50 大衛(wèi) 閱讀(5359) |
評(píng)論 (5) |
編輯 收藏
http://www.nciku.com/
這個(gè)網(wǎng)站里面的手寫輸入真棒!
posted @
2008-09-19 14:15 大衛(wèi) 閱讀(1275) |
評(píng)論 (1) |
編輯 收藏
最近用smartdraw畫了一些結(jié)構(gòu)圖,感覺比visio之類好用,而且也包羅萬象,推薦一下!
下載地址:http://soft.mumayi.net/downinfo/3393.html
posted @
2008-09-18 14:04 大衛(wèi) 閱讀(1854) |
評(píng)論 (2) |
編輯 收藏

/**//* 判斷是否含有GBK以外的特殊字符 */
boolean isGBK(String s) throws UnsupportedEncodingException


{
if(s.equals(new String(s.getBytes("gbk"))))
return true;
else
return false;
}
posted @
2008-09-16 13:04 大衛(wèi) 閱讀(878) |
評(píng)論 (1) |
編輯 收藏
使用這個(gè)組合,感覺還是很方便靈活的。
1、將struts2的json插件加入web工程的lib,jsonplugin的下載地址:
http://code.google.com/p/jsonplugin/downloads/list
2、struts.xml添加專為ajax使用的package
<package name="ajax" extends="json-default">
<action name="ajaxRequest"
class="org.david.struts2.HelloWorld">
<result type="json"></result>
</action>
</package>
3、helloworld.jsp
<SCRIPT type="text/javascript" src="js/jquery-1.2.6.min.js"></script>

<SCRIPT type="text/javascript">
function clickButton()

{
var url = 'ajaxRequest.action';

var params =
{
name:$('#name').attr('value')
};
jQuery.post(url, params, callbackFun, 'json');
}
function callbackFun(data)

{
alert(data.result);//對(duì)應(yīng)HelloWorld類的message屬性
//獲取數(shù)據(jù)后渲染頁面
}
</SCRIPT>




<input id="name" type="text">
<input type="button" value="ok" onclick="javascript:clickButton();">
4、HelloWorld.java
package org.david.struts2;


public class HelloWorld
{

private String name;
private String result;

// ajax請(qǐng)求參數(shù)賦值

public void setName(String name)
{
this.name = name;
}

// ajax返回結(jié)果

public String getResult()
{
return result;
}


public String execute()
{
this.result = "Hello! " + this.name + ".";
return "success";
}

}
posted @
2008-09-07 23:07 大衛(wèi) 閱讀(41960) |
評(píng)論 (17) |
編輯 收藏
鼠標(biāo)手型代碼:
this.style.cursor='pointer'
不要用hand,否則firefox無效。
posted @
2008-08-01 17:03 大衛(wèi) 閱讀(2341) |
評(píng)論 (1) |
編輯 收藏
word-wrap:break-word 在firefox中不會(huì)起作用,以下是解決辦法:
完整的css代碼為
word-wrap:break-word; overflow:hidden;
這段代碼應(yīng)添加到td標(biāo)簽的樣式中。另外,應(yīng)該在外層的table標(biāo)簽中添加樣式
table-layout:fixed;
posted @
2008-07-11 13:34 大衛(wèi) 閱讀(2109) |
評(píng)論 (1) |
編輯 收藏
(.|\s)*
posted @
2008-06-23 14:49 大衛(wèi) 閱讀(925) |
評(píng)論 (0) |
編輯 收藏
按照下面做法,終于成功了!慶祝,紀(jì)念......
背景:某個(gè)系統(tǒng)的mysql數(shù)據(jù)庫(kù)dnname采用默認(rèn)的latin1字符集,系統(tǒng)升級(jí)需要將所有數(shù)據(jù)轉(zhuǎn)換成utf-8格式,目標(biāo)數(shù)據(jù)庫(kù)為newdbname(建庫(kù)時(shí)使用utf8)
方法一:
步驟一 命令行執(zhí)行:mysqldump --opt -hlocalhost -uroot -p*** --default-character-set=lantin1 dbname > /usr/local/dbname.sql
步驟二 將 dbname.sql文件中的create table語句的CHARSET=latin1改為CHARSET=utf8
步驟三 在dbname.sql文件中的insert語句之前加一條'set names utf8;'
步驟四 將dbname.sql轉(zhuǎn)碼為utf-8格式,建議使用UltraEditor,可以直接使用該編輯器的'轉(zhuǎn)換->ASCII到UTF-8(Unicode編輯)',或者將文件另存為UTF-8(無BOM)格式
步驟五 命令行執(zhí)行:mysql -hlocalhost -uroot -p*** --default-character-set=utf8 new_dbname < /usr/local/dbname.sql
總結(jié):這種方法有個(gè)致命之處就是當(dāng)數(shù)據(jù)中有大量中文字符和其他特殊符號(hào)字符時(shí),很有可能導(dǎo)致在[步驟五]時(shí)報(bào)錯(cuò)導(dǎo)致無法正常導(dǎo)入數(shù)據(jù),如果數(shù)據(jù)庫(kù)比較大可以分別對(duì)每張表執(zhí)行上述步驟
方法二(推薦大家使用):
為了解決第一種方法中總結(jié)時(shí)說到的問題,在網(wǎng)上苦苦查找了一天資料才東拼西湊的搞出一個(gè)比較穩(wěn)妥的解決方法
步驟一 將待導(dǎo)出的數(shù)據(jù)表的表結(jié)構(gòu)導(dǎo)出(可以用Phpmyadmin、mysqldump等,很簡(jiǎn)單就不說了),然后將導(dǎo)出的create table語句的CHARSET=latin1改為CHARSET=utf8,在目標(biāo)庫(kù)newdbname中執(zhí)行該create table語句把表結(jié)構(gòu)建好,接下來開始導(dǎo)出-導(dǎo)入數(shù)據(jù)。命令:
./mysqldump -d DB_Dig > /usr/local/tmp/tables.sql
步驟二 命令行:進(jìn)入mysql命令行下,mysql -hlocalhost -uroot -p*** dbname
步驟三 執(zhí)行SQL select * from tbname into outfile '/usr/local/tbname.sql';
步驟四 將tbname.sql轉(zhuǎn)碼為utf-8格式,建議使用UltraEditor,可以直接使用該編輯器的'轉(zhuǎn)換->ASCII到UTF-8(Unicode編輯)',或者將文件另存為UTF-8(無BOM)格式
步驟五 在mysql命令行下執(zhí)行語句 set character_set_database=utf8; 注:設(shè)置mysql的環(huán)境變量,這樣mysql在下一步讀取sql文件時(shí)將以u(píng)tf8的形式去解釋該文件內(nèi)容
步驟六 在mysql命令行下執(zhí)行語句 load data infile 'tbname.sql' into table newdbname.tbname;
注意:千萬不要忘了第四步
采用第二種方法,所有數(shù)據(jù)均正常導(dǎo)入,且格式轉(zhuǎn)換成功沒有亂碼。
參考:http://blog.csdn.net/guoguo1980/archive/2008/01/28/2070701.aspx
--------------------
WE準(zhǔn)高手
posted @
2008-06-11 16:54 大衛(wèi) 閱讀(8969) |
評(píng)論 (8) |
編輯 收藏
編譯:
運(yùn)行junit:
java -cp ../lib/junit.jar:../lib/j2ee.jar:. junit.textui.TestRunner com.chinaren.common.ToolKitTest
posted @
2008-06-10 18:32 大衛(wèi) 閱讀(1197) |
評(píng)論 (0) |
編輯 收藏