java的时间精度(使用Real-Time Java编写Real-Time程序)(转帖)

节自:http://www.huihoo.com/rt_embed/rt/rtj/rtj_rta.html

这里所说的高精度时间,是相对于普通java而言。普通java的时间精度是毫秒,而rtsj的高精度时间可表示的精度为纳秒。

高精度时间用一个64位表示的毫秒值和一个32位表示的纳秒值组成,时间长度就是:

10e64 (毫秒) + 10e32 * 1000 (纳秒) = 时间总和 (毫秒)

这个时间总和相当于大约2.92亿年。

这样,从时间精度上和时间表示长度上,都对以前的java时间做了很大的提升。

不过,现在的软件系统能够响应1个毫秒级也决非易事,更何况是纳秒了。这可能是rtsj规范的制定者对千年虫问题还是心有余悸的缘故吧。

jsp上传文件;jsp上传含中文名的文件(转帖)

转自:http://www.linuxsir.org/bbs/archive/index.php/t-167492.html

LinuxSir.Org > 编程开发讨论区 —— LinuxSir.Org > Java 程序设计开发讨论 > 我想用jsp上传含中文名的文件,该怎么办??

--------------------------------------------------------------------------------

PDA查看完整版本 : 我想用jsp上传含中文名的文件,该怎么办??

--------------------------------------------------------------------------------

pilchard04-12-30, 11:24

上传到服务器以后中文显示不出来?

--------------------------------------------------------------------------------

eTony04-12-30, 11:42

我用的 o'reilly 的上传组件 没有问题

--------------------------------------------------------------------------------

nscwf04-12-30, 12:06

我有个办法,把文件名用POST记下来,上传之后,再更名回来

--------------------------------------------------------------------------------

hantsy04-12-30, 13:42

我用struts上传没有问题,

--------------------------------------------------------------------------------

fangshun05-01-06, 08:47

上传的字节流转换String时需要转码!!!

--------------------------------------------------------------------------------

fangshun05-01-06, 08:53

/**

* 文件上传进行代理服务,阻止不符合上传规范的文件进入。

* 使用单实例创建,外部调用只有通过工厂方法才可以创建唯一的代理实例。

* @author fangshun

* @see FileUploadFactroy

*/

public class FileUploadProxy implements FileUpload {

/**

* 外部调用只有通过工厂方法才可以创建唯一的代理实例。

*/

protected FileUploadProxy() {}

/**

* 上传方法<tt>upload</tt>的代理验证,阻止不符合规范的上传方式,

* 实现接口的方法。

* @param request 需要得到从上传页面传来的request对象。

*

* @param pathName 服务器存放上传文件的绝对路径,

* 这可能来自你自己的指定,或者来自你要解析的某个已经配置好的配置文件

* 例如WEB-INF下的某个目录的xml配置文件

*

* @param sizeMax 需要上传的文件总体的容量,这里使用long类型,以满足

* 能支持大容量的文件上传,请注意:上传参数sizeMax的最小单位为'K'

*

* @throws Exception

* @see FileUpload

*/

public void upload(HttpServletRequest request, String pathName, long sizeMax)

throws Exception {

// TODO Auto-generated method stub

if ((request == null) || (pathName == null)) {

throw new NullPointerException("parameter");

}

if (sizeMax < 0) {

throw new FileSizeException("File Require Size ");

} else {

//从request中获取上下文内容尺度

int requestSize = request.getContentLength();

//为传来的最大容量乘以1024,获得符合以'K'为单位的尺度

long sizeMax_K = sizeMax << 10;

//String pathNameCN = new String(pathName.getBytes("utf-8"), "gb2312");

//如果传来的尺度大于上传的最大限度

if (requestSize > sizeMax_K) {

throw new SizeLimitExceededException(

"the request was rejected because " +

"it's size exceeds allowed range");

}

String contentType = request.getContentType();

//如果传来的条件符合代理类的要求,执行上传操作!!!

JetStepFileUpload upload = JetStepFileUpload.getInstance();

upload.processUpload(request, pathName, sizeMax_K);

}

}

/**

* 上传实现细节

* 内隐类实现

* @author fangshun

*/

private static class JetStepFileUpload {

private static JetStepFileUpload upload;

/**

* 外界对象不能进行实例化,私有创建对象。

*/

private JetStepFileUpload() { }

private static JetStepFileUpload getInstance() {

if(upload == null) {

upload = new JetStepFileUpload();

}

return upload;

}

/**

* 上传实现

* @param request 需要得到从上传页面传来的request对象。

*

* @param pathName 服务器存放上传文件的绝对路径,

* 这可能来自你自己的指定,或者来自你要解析的某个已经配置好的配置文件

* 例如WEB-INF下的某个目录的xml配置文件

*

* @param sizeMax 需要上传的文件总体的容量,这里使用long类型,以满足

* 能支持大容量的文件上传,参数sizeMax的最小单位为'K'

* @throws Exception

*/

private void processUpload(HttpServletRequest request, String filePath, long sizeMax)

throws Exception {

DiskFileUpload fu = new DiskFileUpload();

String encoding = request.getCharacterEncoding();

fu.setHeaderEncoding(encoding);

// If file size exceeds, a FileUploadException will be thrown

fu.setSizeMax(sizeMax);

List fileItems = fu.parseRequest(request);

Iterator itr = fileItems.iterator();

while (itr.hasNext()) {

FileItem fi = (FileItem) itr.next();

String fileName = fi.getName();

if(fileName == null || fileName.equals("")) {

continue;

}

System.out.println("no convert" + fileName);

//fileName = new String(fileName.getBytes(), "utf-8");

// fileName = new String(fileName.getBytes(), "gb2312");

System.out.println("fileName" + fileName);

//Check if not form field so as to only handle the file inputs

//else condition handles the submit button input

if (!fi.isFormField()) {

File file = new File(fileName);

File fNew = new File(filePath, file.getName());

fi.write(fNew);

} else {

System.out.println("Field =" + fi.getFieldName());

}

}

}

}

}

--------------------------------------------------------------------------------

L0veyou05-01-07, 20:36

这是一个用Bean的文件上传JSP,可以识别各种编码.

uploadfile.jsp:

<%@ page language="java"%>

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

<jsp:useBean id="fub" scope="page" class="mybean.FileUploadBean" />

<%

String Dir = "D:\\WWW\\testing\\test"; //保存文件的路径,请确保目录存在,或改到其他目录

//通过调用JavaBeans的方法完成上传操作

fub.setUploadDirectory(Dir);

fub.uploadFile(request);

out.print("<center><font color=red>文件上载成功!</font></center>");

%>

FileUploadBean.java

package mybean;

import java.io.*;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.ServletInputStream;

import javax.servlet.ServletException;

public class FileUploadBean{

private static String newline = "\r\n"; //设定换行符

private String uploadDirectory = "."; //默认的保存位置

private String ContentType = ""; //文件类型

private String CharacterEncoding = ""; //编码格式

//设定文件要保存在服务器中的位置

public void setUploadDirectory(String s){

uploadDirectory = s;

}

//提取文件名,本方法是把用户上传的文件按照原名保存

private String getFileName(String s){

int i = s.lastIndexOf("\\");

if(i < 0 || i >= s.length() - 1){

i = s.lastIndexOf("/");

if(i < 0 || i >= s.length() - 1)

return s;

}

return s.substring(i + 1);

}

//得到content-type

public void setContentType(String s){

ContentType = s;

int j;

if((j = ContentType.indexOf("boundary=")) != -1){

ContentType = ContentType.substring(j + 9);

ContentType = "--" + ContentType;

}

}

//得到文件编码格式

public void setCharacterEncoding(String s){

CharacterEncoding = s;

}

public void uploadFile( HttpServletRequest req) throws ServletException, IOException{

setCharacterEncoding(req.getCharacterEncoding());

setContentType(req.getContentType());

uploadFile(req.getInputStream());

}

public void uploadFile( ServletInputStream servletinputstream) throws ServletException, IOException{

String s5 = null;

String filename = null;

byte Linebyte[] = new byte[4096];

byte outLinebyte[] = new byte[4096];

int ai[] = new int[1];

int ai1[] = new int[1];

String line;

//得到文件名

while((line = readLine(Linebyte, ai, servletinputstream, CharacterEncoding)) != null){

int i = line.indexOf("filename=");

if(i >= 0){

line = line.substring(i + 10);

if((i = line.indexOf("\"")) > 0)

line = line.substring(0, i);

break;

}

}

filename = line;

if(filename != null && !filename.equals("\"")){

filename = getFileName(filename);

String sContentType = readLine(Linebyte, ai, servletinputstream, CharacterEncoding);

if(sContentType.indexOf("Content-Type") >= 0)

readLine(Linebyte, ai, servletinputstream, CharacterEncoding);

//建立新文件的文件句柄

File file = new File(uploadDirectory, filename);

//建立生成新文件的输出流

FileOutputStream fileoutputstream = new FileOutputStream(file);

while((sContentType = readLine(Linebyte, ai, servletinputstream, CharacterEncoding)) != null){

if(sContentType.indexOf(ContentType) == 0 && Linebyte[0] == 45)

break;

if(s5 != null){

//写入新文件

fileoutputstream.write(outLinebyte, 0, ai1[0]);

fileoutputstream.flush();

}

s5 = readLine(outLinebyte, ai1, servletinputstream, CharacterEncoding);

if(s5 == null || s5.indexOf(ContentType) == 0 && outLinebyte[0] == 45)

break;

fileoutputstream.write(Linebyte, 0, ai[0]);

fileoutputstream.flush();

}

byte byte0;

if(newline.length() == 1)

byte0 = 2;

else

byte0 = 1;

if(s5 != null && outLinebyte[0] != 45 && ai1[0] > newline.length() * byte0)

fileoutputstream.write(outLinebyte, 0, ai1[0] - newline.length() * byte0);

if(sContentType != null && Linebyte[0] != 45 && ai[0] > newline.length() * byte0)

fileoutputstream.write(Linebyte, 0, ai[0] - newline.length() * byte0);

fileoutputstream.close();

}

}

//readLine函数把表单提交上来的数据按行读取

private String readLine(byte Linebyte[], int ai[],ServletInputStream servletinputstream,String CharacterEncoding){

try{ //读取一行

ai[0] = servletinputstream.readLine(Linebyte, 0, Linebyte.length);

if(ai[0] == -1)

return null;

}catch(IOException ex){

return null;

}

try{

if(CharacterEncoding == null){

//用默认的编码方式把给定的byte数组转换为字符串

return new String(Linebyte, 0, ai[0]);

}else{

//用给定的编码方式把给定的byte数组转换为字符串

return new String(Linebyte, 0, ai[0], CharacterEncoding);

}

}catch(Exception ex){

return null;

}

}

}

--------------------------------------------------------------------------------

vBulletin v3.5.4,版权所有 ©2000-2006,Jelsoft Enterprises Ltd.

JAVA IDE之烦恼

   在计算机开发语言的历史中,从来没有哪种语言象Java那样受到如此众多厂商的支持,有如此多的开发工具,Java菜鸟们如初入大观园的刘姥姥,看花了眼,不知该何种选择。

    颠来倒去最后在我的那台破电脑上折腾的一个晚上,最后JBUILDER、ECLIPSE和JCREATOR,当然当然还是有JDK的。

    JBUILDER大名鼎鼎的宝兰德公司出品,JBUILDER我的新欢,DILPHI我的最爱;但愿别给你忠实的粉丝下马威了

    ECLIPSE著名开源IDE工具,就冲它开源的模式也要弄上一弄,不过好像上手蛮难的。

    JCREATOR似乎平平无奇,但是编程界面很舒服,而且看起来就比较好用,缺点嘛,还不是很清楚。

    那位大大有空可以帮偶参考一下下

我也可以访问电信网站了^_^(转)

转自:http://blog.matrix.org.cn/page/inclear?entry=%E6%88%91%E4%B9%9F%E5%8F%AF%E4%BB%A5%E8%AE%BF%E9%97%AE%E7%94%B5%E4%BF%A1%E7%BD%91%E7%AB%99%E4%BA%86

我也可以访问电信网站了^_^ 2006年06月05日, 03:07:49 下午 CST in category 自省札记 by inclear

今天在网上看到一个链接,介绍了一种可以解决网通-电信之间互联互通问题的软件,哎呀,这可是困扰了我很久的一个问题,马上去看看。

网址:http://www.tywg.com/

注册了一个用户名,下载了软件,连接上去一看,哇,真的好用哦~~~~~象Matrix,CJSDN等以前访问起来比牛还慢的网站现在都非常流畅,心情顿时大好

不过这个软件仅是目前是免费的,将来看来要收费了,不过,将来的问题将来再说吧,享受先喽

Permalink 留言 [0]

反向跟踪 URL: http://blog.matrix.org.cn/trackback/inclear/Weblog/%E6%88%91%E4%B9%9F%E5%8F%AF%E4%BB%A5%E8%AE%BF%E9%97%AE%E7%94%B5%E4%BF%A1%E7%BD%91%E7%AB%99%E4%BA%86

svhda.exe,Backdoor.Rbot,瑞星也搞不定的病毒

  我是瑞星的正版用户。今天,瑞星提示我一个名叫svhda.exe文件在改写注册表,我当然不会让它改写。用瑞星去查毒,结果一会儿瑞星就自行退出了。在纯dos下查毒也不行,看来是碰到硬货了。

  上网用svhda.exe查了一下,百度没有查到,用google查,有22项,其中包括百度的“百度知道_反病毒_待解决问题”中的一页中文的,看来,前沿的技术性的东西还是google行。估计是这个病毒目前主要是在国外流行,中国还没有流行起来吧。

  最后是根据这个国外论坛的方法解决这个病毒的:http://forums.techguy.org/security/470410-annoying-virus-please-help.html

  真正解决问题的是一个叫作:Ewido Security Suite的软件。

  使用说明如上面论坛的:

  


27-May-2006 11:40 AM 

 Cheeseball81  

Moderator  Posts: 44,883

Join Date: Mar 2004

Location: New York

Experience: Nerd

 

* Click here to download the trial version of Ewido Security Suite.

· Install Ewido.

· During the installation, under "Additional Options" uncheck "Install background guard" and "Install scan via context menu".

· Launch ewido.

· It will prompt you to update click the OK button and it will go to the main screen.

· On the left side of the main screen click update.

· Click on Start and let it update.

· DO NOT run a scan yet.

Restart your computer into Safe Mode now.

(Start tapping the F8 key at Startup, before the Windows logo screen).

Perform the following steps in Safe Mode:

* Run Ewido:

Click on scanner

Click Complete System Scan and the scan will begin.

During the scan it will prompt you to clean files, click OK.

When the scan is finished, look at the bottom of the screen and click the Save report button.

Save the report to your desktop.

Reboot.

   

  使用截图如下:



另外,其中还介绍一个叫作Hijack This的软件,英文不大懂,好像是一个查看、删除常驻内存进程的工具。论坛中的作用就是用它,在上面那个Ewido执行前和后来查看比较内存中的进程的。正如下面所说,它查出来的东西不一定是病毒,有些是系统的和用户定制的。

使用说明如下:


26-May-2006 03:41 PM 

 Cheeseball81  

Moderator  Posts: 44,883

Join Date: Mar 2004

Location: New York

Experience: Nerd

 

Hi and welcome

* Click here to download HJTsetup.exe.

Save HJTsetup.exe to your desktop.

Double click on the HJTsetup.exe icon on your desktop.

By default it will install to C:\Program Files\Hijack This.

Continue to click Next in the setup dialogue boxes until you get to the Select Addition Tasks dialogue.

Put a check by Create a desktop icon then click Next again.

Continue to follow the rest of the prompts from there.

At the final dialogue box click Finish and it will launch Hijack This.

Click on the Do a system scan and save a log file button. It will scan and then ask you to save the log.

Click Save to save the log file and then the log will open in notepad.

Click on "Edit > Select All" then click on "Edit > Copy" to copy the entire contents of the log.

Come back here to this thread and Paste the log in your next reply.

DO NOT have Hijack This fix anything yet. Most of what it finds will be harmless or even required.

__________________

Peter: Oh my god Brian, there's a message in my Alpha-Bits. It says, 'Oooooo.'

Brian: Peter, those are Cheerios.

Member of ASAP

Microsoft MVP/Windows - Security

If we've helped, please donate to TSG.

使用截图如下:



问题:搞不懂HttpServletRequest的getCharacterEncoding()方法了

运行Struts中那个upload的例子,当使用那个upload-utf8.jsp上传文件时,上传后转到display.jsp时,显的总是乱码。就算在display.jsp中设置了<%@ page contentType="text/html; charset=utf-8" %>也没有用。

如下:

upload-utf8.jsp的设置:


<%@ page language="java" contentType="text/html; charset=gbk" %>

action:


            String encoding = request.getCharacterEncoding();

            System.out.println("the encoding is: "+ encoding);

            if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8")))

            {

                response.setContentType("text/html; charset=utf-8");

            }

虽然在upload-utf8.jsp中也指定了utf8编码,但是在request.getCharacterEncoding();得到的encoding总是null,也就是没有在request中没有指定编码,明明是指定了的呀?怪事。

还有,就是那个upload.jsp,在昨天的运行中还是在display.jsp中出现了乱码,可是今天却没有了,搞不懂,怪事。

初识

编程年龄也有6年多了,都是再使用DELPHI和C++等,最近刚开始学习JAVA语言,对这个领域相对很陌生,基本上算是从0开始。

所谓万丈高楼平地起,什么事情都要一步一步来。

这两天接触并查阅了大量的关于JAVA的资料,发现说它是一个庞大的家族并不为过,相反自己倒有点看的头晕目眩的了,为了不迷失在这片茂密的JAVA森林里面,决定定下初步的学习方向,由于本人过去做的都是基于C/S结构的应用程序,所以现在本人将目标放在了B/S的目标上面。

提起JAVA首先几乎所有程序员都知道它的语言的开放性和在世界级的广泛应用(相形之下本人以前学习的DELPHI和C++都可怜的很),而且还有伴随着JAVA的J2EE/J2ME等等架构。

我学习的第一个疑问就是J2EE究竟是什么,它到底有什么用处?

翻阅了很多网络上的资料,但是发现各位发资料的大大们好像都是高手中的高手,将一个J2EE写的惊天动地的,看了半天也完全没看明白。最后只好清楚的认识到自己的水平实在太低了,遂打消掉一步登天的念头决定从最简单的开始做起。