
工程目录
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>
<!-- 第一 这个过滤器与Struts的核心过滤器协同工作,以便更容易与sitemesh整合 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<!-- 第二 sitemesh的过滤器,同时也整合了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标签,使用方式:<#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后不会丢失 -->
<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插件,实现约定大于配置的零配置文件风格.
特殊的Result路径在Action类中使用@Result设定.
-->
</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 大卫 阅读(3289) |
评论 (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 大卫 阅读(1750) |
评论 (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 值仅用于开发环境,生产环境请设置为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准高手
posted @
2009-11-25 15:02 大卫 阅读(5062) |
评论 (1) |
编辑 收藏
RT
太保守会影响效率,当某些代码逻辑是认为可控制时,不用保守。
posted @
2009-09-28 10:08 大卫 阅读(426) |
评论 (0) |
编辑 收藏
关于类的划分,上层应该按业务领域含义划分,下层应该按实现细节划分。
posted @
2009-09-27 12:10 大卫 阅读(412) |
评论 (0) |
编辑 收藏
其实很简单,就把标记@Id放在主键(非自增)上就OK了。
posted @
2009-02-25 14:12 大卫 阅读(2554) |
评论 (0) |
编辑 收藏
摘要: 在设计数据库表的时候,往往会设计出带有复合主键的表,即表的记录由多个字段联合标识,如:
表
CREATE TABLE TB_HOUR_DATA
(
STAT_DATE DATE &...
阅读全文
posted @
2009-02-25 14:10 大卫 阅读(3001) |
评论 (2) |
编辑 收藏
如何调用执行iframe中的方法?如下:
document.getElementById("iframeId").contentWindow.functionName();
posted @
2008-10-07 14:50 大卫 阅读(5356) |
评论 (5) |
编辑 收藏
http://www.nciku.com/
这个网站里面的手写输入真棒!
posted @
2008-09-19 14:15 大卫 阅读(1273) |
评论 (1) |
编辑 收藏
最近用smartdraw画了一些结构图,感觉比visio之类好用,而且也包罗万象,推荐一下!
下载地址:http://soft.mumayi.net/downinfo/3393.html
posted @
2008-09-18 14:04 大卫 阅读(1852) |
评论 (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 大卫 阅读(875) |
评论 (1) |
编辑 收藏
使用这个组合,感觉还是很方便灵活的。
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);//对应HelloWorld类的message属性
//获取数据后渲染页面
}
</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请求参数赋值

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

// ajax返回结果

public String getResult()
{
return result;
}


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

}
posted @
2008-09-07 23:07 大卫 阅读(41955) |
评论 (17) |
编辑 收藏
鼠标手型代码:
this.style.cursor='pointer'
不要用hand,否则firefox无效。
posted @
2008-08-01 17:03 大卫 阅读(2338) |
评论 (1) |
编辑 收藏
word-wrap:break-word 在firefox中不会起作用,以下是解决办法:
完整的css代码为
word-wrap:break-word; overflow:hidden;
这段代码应添加到td标签的样式中。另外,应该在外层的table标签中添加样式
table-layout:fixed;
posted @
2008-07-11 13:34 大卫 阅读(2103) |
评论 (1) |
编辑 收藏
(.|\s)*
posted @
2008-06-23 14:49 大卫 阅读(924) |
评论 (0) |
编辑 收藏
按照下面做法,终于成功了!庆祝,纪念......
背景:某个系统的mysql数据库dnname采用默认的latin1字符集,系统升级需要将所有数据转换成utf-8格式,目标数据库为newdbname(建库时使用utf8)
方法一:
步骤一 命令行执行: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转码为utf-8格式,建议使用UltraEditor,可以直接使用该编辑器的'转换->ASCII到UTF-8(Unicode编辑)',或者将文件另存为UTF-8(无BOM)格式
步骤五 命令行执行:mysql -hlocalhost -uroot -p*** --default-character-set=utf8 new_dbname < /usr/local/dbname.sql
总结:这种方法有个致命之处就是当数据中有大量中文字符和其他特殊符号字符时,很有可能导致在[步骤五]时报错导致无法正常导入数据,如果数据库比较大可以分别对每张表执行上述步骤
方法二(推荐大家使用):
为了解决第一种方法中总结时说到的问题,在网上苦苦查找了一天资料才东拼西凑的搞出一个比较稳妥的解决方法
步骤一 将待导出的数据表的表结构导出(可以用Phpmyadmin、mysqldump等,很简单就不说了),然后将导出的create table语句的CHARSET=latin1改为CHARSET=utf8,在目标库newdbname中执行该create table语句把表结构建好,接下来开始导出-导入数据。命令:
./mysqldump -d DB_Dig > /usr/local/tmp/tables.sql
步骤二 命令行:进入mysql命令行下,mysql -hlocalhost -uroot -p*** dbname
步骤三 执行SQL select * from tbname into outfile '/usr/local/tbname.sql';
步骤四 将tbname.sql转码为utf-8格式,建议使用UltraEditor,可以直接使用该编辑器的'转换->ASCII到UTF-8(Unicode编辑)',或者将文件另存为UTF-8(无BOM)格式
步骤五 在mysql命令行下执行语句 set character_set_database=utf8; 注:设置mysql的环境变量,这样mysql在下一步读取sql文件时将以utf8的形式去解释该文件内容
步骤六 在mysql命令行下执行语句 load data infile 'tbname.sql' into table newdbname.tbname;
注意:千万不要忘了第四步
采用第二种方法,所有数据均正常导入,且格式转换成功没有乱码。
参考:http://blog.csdn.net/guoguo1980/archive/2008/01/28/2070701.aspx
--------------------
WE准高手
posted @
2008-06-11 16:54 大卫 阅读(8963) |
评论 (8) |
编辑 收藏
编译:
运行junit:
java -cp ../lib/junit.jar:../lib/j2ee.jar:. junit.textui.TestRunner com.chinaren.common.ToolKitTest
posted @
2008-06-10 18:32 大卫 阅读(1194) |
评论 (0) |
编辑 收藏
build.xml
1
<?xml version="1.0"?>
2
<project name="anttest" default="run">
3
<property name="build.path" value="build/classes/"/>
4
<path id="compile.classpath">
5
<fileset dir="lib">
6
<include name="*.jar"/>
7
</fileset>
8
</path>
9
10
<target name="init">
11
<mkdir dir="${build.path}" />
12
<mkdir dir="dist" />
13
</target>
14
<target name="compile" depends="init">
15
<javac srcdir="src/" destdir="${build.path}" classpath="${build.path}">
16
<classpath refid="compile.classpath"/>
17
</javac>
18
<echo>compilation complete!</echo>
19
</target>
20
<target name="run" depends="compile">
21
<java classname="org.test.work.HelloWorld" classpath="${build.path}" />
22
<echo>Run complete!</echo>
23
</target>
24
25
<target name="test" depends="compile">
26
<junit printsummary="on" haltonfailure="true" showoutput="true">
27
<classpath refid="compile.classpath"/>
28
<classpath path="${build.path}"/>
29
<formatter type="xml" />
30
<test name="org.test.work.HelloWorldTest"/>
31
</junit>
32
</target>
33
34
</project>
HelloWorld.java
1
package org.test.work;
2
3
public class HelloWorld
{
4
5
public String showMessage()
{
6
return "Hello world!!!";
7
}
8
9
public static void main(String[] args)
{
10
11
System.out.println("Hello world!!!");
12
}
13
}
HelloWorldTest.java
1
package org.test.work;
2
3
import static org.junit.Assert.*;
4
import org.junit.*;
5
6
import org.test.work.HelloWorld;
7
8
public class HelloWorldTest
{
9
10
private static HelloWorld hw = null;
11
12
@BeforeClass
13
public static void setUp()
{
14
hw = new HelloWorld();
15
}
16
17
@Test
18
public void showHelloWorld()
{
19
assertEquals(hw.showMessage(),"Hello world!!!");
20
}
21
22
@AfterClass
23
public static void tearDown()
{
24
hw = null;
25
}
26
27
}
posted @
2008-06-09 20:24 大卫 阅读(426) |
评论 (0) |
编辑 收藏
JSP+jQuery+Spring+iBatis
posted @
2008-05-29 21:06 大卫 阅读(269) |
评论 (0) |
编辑 收藏
编译:
1
D:\je-3.2.76\examples\je>javac -classpath ..\..\lib\je-3.2.76.jar .\SimpleExample.java
执行:
D:\je-3.2.76\examples>java -classpath .\;..\lib\je-3.2.76.jar je.SimpleExample
posted @
2008-05-07 15:28 大卫 阅读(452) |
评论 (1) |
编辑 收藏
超级简单的一段代码,通过正则表达式获取字符串中某部分的值,代码:
1
/** *//**
2
* 这段代码就是要获取到字符串"2008-05-10"的月份值及日期
3
*/
4
5
Pattern pattern = Pattern.compile("[0-9]{4}-([0-9]{1,2})-([0-9]{1,2})");//括号用于组获取
6
Matcher matcher = pattern.matcher("2008-05-10");
7
8
int i = 0;
9
//循环只运行了一次
10
while(matcher.find())
11
{
12
System.out.println(++i);
13
System.out.println(matcher.group(0));//组0为全部串值
14
System.out.println(matcher.group(1));//pattern模式中中间的括号中的为组1
15
System.out.println(matcher.group(2));//pattern模式中后面的括号中的为组2
16
}
posted @
2008-05-05 18:16 大卫 阅读(1076) |
评论 (0) |
编辑 收藏
执行如下批处理:
1
@echo off
2
echo 正在清除系统垃圾文件,请稍等
3
del /f /s /q %systemdrive%\*.tmp
4
del /f /s /q %systemdrive%\*._mp
5
del /f /s /q %systemdrive%\*.log
6
del /f /s /q %systemdrive%\*.gid
7
del /f /s /q %systemdrive%\*.chk
8
del /f /s /q %systemdrive%\*.old
9
del /f /s /q %systemdrive%\recycled\*.*
10
del /f /s /q %windir%\*.bak
11
del /f /s /q %windir%\prefetch\*.*
12
rd /s /q %windir%\temp & md %windir%\temp
13
del /f /q %userprofile%\小甜饼s\*.*
14
del /f /q %userprofile%\recent\*.*
15
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"
16
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
17
del /f /s /q "%userprofile%\recent\*.*"
18
echo 清除系统LJ完成!
19
echo. & pause
绝对安全!
--------------------
WE准高手
posted @
2008-03-30 18:22 大卫 阅读(1637) |
评论 (8) |
编辑 收藏
数据格式:
1
var folders=[
{'folderId':'1','folderName':'收信箱'},
{'folderId':'2','folderName':'发信箱'}];
2
3
//用于下拉列表的store
4
var foldersJsonStore = new Ext.data.SimpleStore(
{
5
fields: [
{name: 'folderId', mapping:'folderId'},
{name: 'folderName', mapping:'folderName'}],
6
data: folders
7
});
刷新数据:
1
foldersJsonStore.loadData(folders);
下拉框组件:
1
var combo = new Ext.form.ComboBox(
{
2
fieldLabel: '文件夹',
3
name: 'folderMoveTo',
4
store: foldersJsonStore,
5
displayField: 'folderName',
6
valueField: 'folderId',
7
mode: 'local',
8
typeAhead: true, //自动将第一个搜索到的选项补全输入
9
triggerAction: 'all',
10
emptyText: '全部',
11
selectOnFocus: true,
12
forceSelection: true
13
})
--------------------
WE准高手
posted @
2008-03-28 15:07 大卫 阅读(5624) |
评论 (4) |
编辑 收藏
摘要: 在使用Ext与DWR框架时,我们往往会用到GridPanel组件搭配PagingToolbar组件来实现翻页数据列表。翻页的时候每一页都要从后台获取该页的数据列表信息。
在解决此问题时,花了不少时间,看过不少前人的代码,终于成功了!共享之。
关键代码如下:
Store为:
1var ds = new Ext.data.Store({
...
阅读全文
posted @
2008-03-20 13:51 大卫 阅读(6938) |
评论 (1) |
编辑 收藏
一、配置
在页面中添加:
1
<script type='text/javascript' src='dwr/interface/Folder.js'>
2
</script>
3
<script type='text/javascript' src='dwr/engine.js'>
4
</script>
5
<script type='text/javascript' src='dwr/util.js'>
6
</script>
需要注意的是路径,而不是官方的:
1
<script type='text/javascript' src='../interface/Folder.js'></script>
2
<script type='text/javascript' src='../engine.js'></script>
3
<script type='text/javascript' src='../util.js'></script>
二、返回的json串需要进行处理,才可以在前台javascript正确处理。
使用json-lib的JSONArray对List类型数据进行处理:
1
JSONArray.fromObject(folders).toString();
返回List型的json数据为:
1
[
{"folderId":1,"folderName":"收信箱"},
{"folderId":2,"folderName":"发信箱"},
{"folderId":3,"folderName":"草稿箱"},
{"folderId":4,"folderName":"回收站"},
{"folderId":5,"folderName":"垃圾箱"}]
这个数据返回到前台一定要用Ext.util.JSON.decode(data)进行编码,否则javascript不能正常处理。
1
//刷新文件夹列表,DWR获取数据。
2
function initFolders()
{
3
Folder.getFolderList(refrashFolders);}
4
5
function refrashFolders(data)
{
6
folders = Ext.util.JSON.decode(data);//一定要用这个进行解码
7
initFolderTreeNode();}
--------------------
WE准高手
posted @
2008-03-14 10:21 大卫 阅读(2419) |
评论 (1) |
编辑 收藏
摘要: 页面代码:
1<html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; ch...
阅读全文
posted @
2008-03-07 16:11 大卫 阅读(5085) |
评论 (1) |
编辑 收藏
1
package test;
2
3
import java.lang.reflect.Method;
4
import java.lang.reflect.ParameterizedType;
5
import java.lang.reflect.Type;
6
import java.util.List;
7
import java.util.Map;
8
9
public class TempTest
{
10
11
public static void main(String[] args) throws Exception
{
12
Method[] methods = TempTest.class.getDeclaredMethods();
13
for (Method method : methods)
{
14
System.out.println("method:" + method.getName());// 方法名
15
16
// //////////////方法的参数
17
System.out.println(" paramTypeType: ");
18
Type[] paramTypeList = method.getGenericParameterTypes();// 方法的参数列表
19
for (Type paramType : paramTypeList)
{
20
System.out.println(" " + paramType);// 参数类型
21
if (paramType instanceof ParameterizedType)/**//* 如果是泛型类型 */
{
22
Type[] types = ((ParameterizedType) paramType)
23
.getActualTypeArguments();// 泛型类型列表
24
System.out.println(" TypeArgument: ");
25
for (Type type : types)
{
26
System.out.println(" " + type);
27
}
28
}
29
}
30
31
// //////////////方法的返回值
32
System.out.println(" returnType: ");
33
Type returnType = method.getGenericReturnType();// 返回类型
34
System.out.println(" " + returnType);
35
if (returnType instanceof ParameterizedType)/**//* 如果是泛型类型 */
{
36
Type[] types = ((ParameterizedType) returnType)
37
.getActualTypeArguments();// 泛型类型列表
38
System.out.println(" TypeArgument: ");
39
for (Type type : types)
{
40
System.out.println(" " + type);
41
}
42
}
43
44
}
45
46
}
47
48
public static String method1(List list)
{
49
return null;
50
}
51
52
private static Map<String, Double> method2(Map<String, Object> map)
{
53
return null;
54
}
55
56
}
posted @
2008-02-28 10:29 大卫 阅读(5809) |
评论 (3) |
编辑 收藏
算法程序题:
该公司笔试题就1个,要求在10分钟内作完。
题目如下:用1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列,如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连。
基本思路:
1 把问题归结为图结构的遍历问题。实际上6个数字就是六个结点,把六个结点连接成无向连通图,对于每一个结点求这个图形的遍历路径,所有结点的遍历路径就是最后对这6个数字的排列组合结果集。
2 显然这个结果集还未达到题目的要求。从以下几个方面考虑:
1. 3,5不能相连:实际要求这个连通图的结点3,5之间不能连通, 可在构造图结构时就满足改条件,然后再遍历图。
2. 不能有重复: 考虑到有两个2,明显会存在重复结果,可以把结果集放在TreeSet中过滤重复结果。//TreeSet用于过滤一个集合中相同的东西还真是个挺不错的方法
3. 4不能在第三位: 仍旧在结果集中去除满足此条件的结果。
采用二维数组定义图结构,最后的代码是:
1
package test;
2
3
import java.util.Iterator;
4
import java.util.TreeSet;
5
6
public class TestQuestion
{
7
8
private String[] b = new String[]
{ "1", "2", "2", "3", "4", "5" };
9
private int n = b.length;
10
private boolean[] visited = new boolean[n];
11
private int[][] a = new int[n][n];
12
private String result = "";
13
private TreeSet treeSet = new TreeSet();// 用于保存结果,具有过滤相同结果的作用。
14
15
public static void main(String[] args)
{
16
new TestQuestion().start();
17
}
18
19
private void start()
{
20
// 创建合法路径标识集合
21
for (int i = 0; i < n; i++)
{
22
for (int j = 0; j < n; j++)
{
23
if (i == j)
{
24
a[i][j] = 0;
25
} else
{
26
a[i][j] = 1;
27
}
28
}
29
}
30
a[3][5] = 0;
31
a[5][3] = 0;
32
for (int i = 0; i < n; i++)
{
33
this.depthFirstSearch(i);// 深度递归遍历
34
}
35
Iterator it = treeSet.iterator();
36
while (it.hasNext())
{
37
String string = (String) it.next();
38
39
if (string.indexOf("4") != 2)
{
40
System.out.println(string);
41
}
42
}
43
}
44
45
/** *//**
46
* 深度优先遍历
47
*
48
* @param startIndex
49
*/
50
private void depthFirstSearch(int startIndex)
{
51
// 递归的工作
52
visited[startIndex] = true;// 用于标识已经走过的节点
53
result = result + b[startIndex];// 构造结果
54
if (result.length() == n)
{
55
treeSet.add(result);// 添加到TreeSet类型中,具有过滤相同结果的作用
56
}
57
// 每走到一个节点,挨个遍历下一个节点
58
for (int j = 0; j < n; j++)
{
59
if (a[startIndex][j] == 1 && visited[j] == false)
{
60
depthFirstSearch(j);// 深度递归遍历
61
} else
{
62
continue;
63
}
64
}
65
// 递归的收尾工作
66
result = result.substring(0, result.length() - 1);
67
visited[startIndex] = false;// 取消访问标识
68
}
69
}
70
--------------------
WE准高手
posted @
2008-02-27 14:30 大卫 阅读(2991) |
评论 (12) |
编辑 收藏
TreeSet类型是J2SE中唯一可实现自动排序的类型,用法如下:
MyComparator.java
1
package test;
2
3
import java.util.Comparator;
4
5
public class MyComparator<T> implements Comparator<T>
{
6
7
public int compare(T arg0, T arg1)
{
8
if (arg0.equals(arg1))
{
9
return 0;
10
}
11
return ((Comparable<T>) arg0).compareTo(arg1) * -1;
12
}
13
14
}
TreeSetTest.java
1
package test;
2
3
import java.util.Iterator;
4
import java.util.TreeSet;
5
6
public class TreeSetTest
{
7
8
/** *//**
9
* @param args
10
*/
11
public static void main(String[] args)
{
12
13
MyComparator<String> myComparator = new MyComparator<String>();
14
15
// /////////////////////不添加自定义排序
16
TreeSet<String> treeSet1 = new TreeSet<String>();
17
treeSet1.add("c");
18
treeSet1.add("a");
19
treeSet1.add("b");
20
21
Iterator<String> iterator1 = treeSet1.iterator();
22
while (iterator1.hasNext())
{
23
System.out.println(iterator1.next());
24
}
25
26
// /////////////////////添加自定义排序
27
TreeSet<String> treeSet2 = new TreeSet<String>(myComparator);
28
treeSet2.add("c");
29
treeSet2.add("a");
30
treeSet2.add("b");
31
32
Iterator<String> iterator2 = treeSet2.iterator();
33
while (iterator2.hasNext())
{
34
System.out.println(iterator2.next());
35
}
36
}
37
38
}
39
运行结果:
--------------------
WE准高手
posted @
2008-02-27 13:34 大卫 阅读(8426) |
评论 (3) |
编辑 收藏
假设要添加库文件
richfaces-ui-3.1.3.GA.jar
1、为库
richfaces-ui-3.1.3.GA.jar文件建立pom文件
richfaces-ui-3.1.3.GA.pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>
4.0.0</modelVersion>
<groupId>
org.richfaces</groupId>
<artifactId>
richfaces-ui</artifactId>
<version>
3.1.3.GA</version>
<name>RichFaces JSF components library</name>
<packaging>jar</packaging>
</project>
2、用ant为jar和pom文件分别生成校验文件.sha1
<project default="main">
<target name="main" description="Generate checksum file for jar and pom">
<checksum algorithm="SHA" fileext=".sha1">
<fileset dir="
F:/software/java/richfaces-ui-3.1.3.GA/lib" id="id">
<include name="**/*.pom" />
<include name="**/*.jar" />
<include name="**/*.xml" />
<exclude name="**/*.sh1" />
</fileset>
</checksum>
</target>
</project>
3、在.m2目录中创建该库文件的代码库目录
.m2\repository\org\richfaces\richfaces-ui\3.1.3.GA
其中,
org\richfaces为包路径,
richfaces-ui为包名,
3.1.3.GA为版本,这三项是与pom文件中的
groupId,artifactId,version分别对应的。
将
richfaces-ui-3.1.3.GA.jar,richfaces-ui-3.1.3.GA.jar.sha1,richfaces-ui-3.1.3.GA.pom,richfaces-ui-3.1.3.GA.pom.sha1拷贝到该目录下。
4、在工程的pom文件中添加依赖
<dependency>
<groupId>
org.richfaces</groupId>
<artifactId>
richfaces-ui</artifactId>
<version>
3.1.3.GA</version>
</dependency>
--------------------
WE准高手
posted @
2008-02-12 15:07 大卫 阅读(1451) |
评论 (0) |
编辑 收藏
1、mvn archetype:create -DgroupId=org.david.app -DartifactId=mywebapp -DarchetypeArtifactId=maven-archetype-webapp
2、cd mywebapp
mvn eclipse:eclipse
导入eclipse工程
(或者直接从eclipse中导入maven工程)
3、添加servlet依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
4、添加源代码目录src/main/java
将源代码放在该目录下。
5、添加jetty插件
<build>
<finalName>mywebapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
6、用jetty调试(http://www.blogjava.net/alwayscy/archive/2007/06/01/118584.html)
命令行:mvn jetty:run
或者
1、先来配置一个外部工具,来运行JETTY:
选择菜单Run->External Tools->External Tools ...在左边选择Program,再点New:
配置
Location为mvn完整命令行。定位到bin下的mvn.bat
选择
Working Directory为本项目。
Arguments填写:jetty:run
再点选Enviroment页:加入MAVEN_OPTS变量,值为:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=
8080,server=y,suspend=
y
其中,如果suspend=n 表示不调试,直接运行。address=8080为端口
然后,点APPLY,再关闭本对话框。
另外注意一点,好像external tool菜单项在java browering的perspective下才会出现。如果在java下看不见,可以切换下试试。
启动jetty
2、调试应用
点选run->debug...
选中左树中的Remote Java Application,再点New。
选择你的项目,关键是要填和之前设置外部工具时相同的端口号。
--------------------
WE准高手
posted @
2008-02-12 15:05 大卫 阅读(6491) |
评论 (1) |
编辑 收藏