Archive for category Java方面

解决eclipse-helios中Errors running builder JavaScript Validator的问题

最近下载了eclipse-jee-helios-win32.zip版,使用起来没感觉到什么变化,就是以前的Web项目上在打开的时候,总是在验证的时候弹出错误:

Errors occurred during the build.
Errors running builder 'JavaScript Validator' on project '##'.
java.lang.NullPointerException

要解决这个问题,要就把JavaScript Validator去掉。去掉的方法是:选择一个项目—-右键Properties—-Builders(排二个)—-点一下右则会有四项—-取消第一项“JavaScript Validator”的勾就OK了

在eclipse中使用tfs

要在eclipse中连接到Team Foundation Server,需要到微软的网站上下载一个插件:TFSEclipsePlugin-UpdateSiteArchive-10.0.0.zip,在页面的下方,点击download就可以了。

下载完成之后,就打开eclipse在Help–Install New Software中安装Achieve,安装好了之后,会要求重启,然后在window–preferences–Team–Team Foundation Server–Product Key中输入:“7W3RJ-4WX3R-BV8JM-FC8P7-3W7QX”,这样就可以使用eclipse操作tfs了。

操作tfs与在vs2008中基本一致的,保持了微软一贯的简便性。

tomcat 7: IllegalArgumentException: taglib definition not consistent with specification version

最近下载了tomcat7,部署了还来的系统,发现报tomcat 7: IllegalArgumentException: taglib definition not consistent with specification version错误,仔细查找一下发现,原来在web.xml中,针对taglib节点有了新的配置要求,原来的:

<web-app>
	<taglib>
		<taglib-uri>/WEB-INF/tlds/PortalModule.tld</taglib-uri>
		<taglib-location>/WEB-INF/tlds/PortalModule.tld</taglib-location>
	</taglib>
</web-app>

现在的:

<web-app>
	<jsp-config>
	        <taglib>
		         <taglib-uri>/WEB-INF/tlds/PortalModule.tld</taglib-uri>
		         <taglib-location>/WEB-INF/tlds/PortalModule.tld</taglib-location>
	        </taglib>
	</jsp-config>
</web-app>

java使用jacob调用c#.net程序

必备程序:jacob,下载地址为:jacobBin_17.zip
一、使用vs2008或者vs2010新建一个Windows类库程序,项目名称就叫InvokeCSharp,再新建一个类:ExampleClass,具体代码如下: Read the rest of this entry »

用Java实现Google的“您是不是要找”功能

[转自InfoQ,原文地址:用Java实现Google的“您是不是要找”功能]
引言

很多人在使用搜索引擎的时候,会出于各种原因,拼错想要搜索的关键字,比如键盘有问题(某个按键坏了)、不熟悉国际名称(弗洛伊德的全名Sigmund Freud)、不小心写错字母(Sinpsons)或多写了一个字母(Frusciaante)。许多用户都很熟悉Google搜索引擎携带的“您是不是要找”功能。这个功能在检测到搜索关键字有可能拼写错了的时候会提供一些备选建议。

Read the rest of this entry »

用Java实现断点续传(HTTP)【转】

原文地址:用Java实现断点续传(HTTP)
断点续传的原理
其实断点续传的原理很简单,就是在Http的请求上和一般的下载有所不同而已。
打个比方,浏览器请求服务器上的一个文时,所发出的请求如下:
假设服务器域名为wwww.sjtu.edu.cn,文件名为down.zip。
GET /down.zip HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-
excel, application/msword, application/vnd.ms-powerpoint, */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Connection: Keep-Alive
服务器收到请求后,按要求寻找请求的文件,提取文件的信息,然后返回给浏览器,返回信息如下:
200
Content-Length=106786028
Accept-Ranges=bytes
Date=Mon, 30 Apr 2001 12:56:11 GMT
ETag=W/”02ca57e173c11:95b”
Content-Type=application/octet-stream
Server=Microsoft-IIS/5.0
Last-Modified=Mon, 30 Apr 2001 12:56:11 GMT
所谓断点续传,也就是要从文件已经下载的地方开始继续下载。所以在客户端浏览器传给 Web服务器的时候要多加一条信息–从哪里开始。 Read the rest of this entry »

java性能优化的两本书

《Java2 performance and Idiom Guide》(Prentice Hall,1999) 作者:Craig Larman和Rhett Guthrie
《Server-Side Programming Techniques(Java Performance and Scalability,Volume 1)》(Addison-Wesley,2000) 作者:Dov Bulka

在java中解析xslt的代码

通常情况下,我们都使用xslt来解析xml文件,然后生成网页。在C#中有自带的xml控件,可以指定xml与xslt就能输出了,而在java,这一步要自己实现,以下是实现的代码,最终生成html代码,并取第38个字符以后的所有内容,主要是去掉了xml声明头。
Read the rest of this entry »

java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested的解决方法

java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
	at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623)
	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
	at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:420)
	at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:896)
	at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:986)
	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888)
	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2929)
	at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

解决方法:将你连接的oracle数据库的驱动包放到你的lib下,更新了oracle驱动包就可以了。

判断一个图片中两个区域的位置关系

以图片左上角为(0,0),以区域A(x,y,width,height)为中心,A矩形的中心位置为(x0,y0),B(x,y,width,height)为界面中圆上“上下左右”四个方向的一个位置,B矩形中心位置为(x1,y1)。
A在B内
B.x < A.x 且 A.x+A.width < B.x + B.width
B.y < A.y 且 A.y + A.height < B.y + B.height

其他四个方位角度的计算
alpha= Arcsin(abs(y1-y0)/sqrt((y1-y0)2+(x1-x0)2))*180/Pi
最后得到的角度theta值是根据alpha以及x1-x0,y1-y0的符号不同用下表中的条件加以判断
21

用代码表示:

/**
 * 判断一个图片的两个区域的位置关系
 * @param q1 图片中区域1
 * @param q2 图片中区域2
 * @param direction 12345对应上下左右中
 * @return 是否在指定的位置上
 */
private boolean judgeDirection(ImageRect q2, ImageRect q1, String direction)
{
	boolean value = false;
	int idirection = Integer.parseInt(direction);
	String[] q1_dot = q1.getRegion_dot().split(",");
	String[] q2_dot = q2.getRegion_dot().split(",");
	double x0 = Double.parseDouble(q1_dot[0]);
	double y0 = Double.parseDouble(q1_dot[1]);
	double x1 = Double.parseDouble(q2_dot[0]);
	double y1 = Double.parseDouble(q2_dot[1]);
	double alpha = Math.asin(Math.abs(y1 - y0) / Math.sqrt((Math.pow((y1 - y0), 2) + Math.pow((x1 - x0), 2)))) * 180 / Math.PI;
	double theta = alpha;
	if ((x1 - x0) > 0 && (y1 - y0) <= 0)
	{
		theta = alpha;
	}
	else if ((x1 - x0) <= 0 && (y1 - y0) < 0)
	{
		theta = 180 - alpha;
	}
	else if ((x1 - x0) < 0 && (y1 - y0) >= 0)
	{
		theta = 180 + alpha;
	}
	else if ((x1 - x0) >= 0 && (y1 - y0) > 0)
	{
		theta = 360 - alpha;
	}
	switch (idirection)
	{
		case 1:
			value = 45 <= theta && theta <= 135;
			break;
		case 2:
			value = 225 <= theta && theta <= 315;
			break;
		case 3:
			value = 135 < theta && theta < 225;
			break;
		case 4:
			value = (0 < theta && theta < 45) || (315 < theta && theta < 360);
			break;
		case 5:
			value = q2.getX() < q1.getX() && (q1.getX() + q1.getRegion_width()) < (q2.getX() + q2.getRegion_width()) && q2.getY() < q1.getY() && (q1.getY() + q1.getRegion_height()) < (q2.getY() + q2.getRegion_height());
			break;
	}
	return value;
}
pagepeel by webpicasso.de