存档

‘程序设计’ 分类的存档

SmartUpload与ftp两种上传方式的合并

2010年1月2日 root 没有评论

<%@ page language="java" import="com.jspsmart.upload.*" import="java.text.*,java.util.*,java.io.*,org.apache.commons.net.ftp.*"%>
<%@ page contentType="text/html;charset=GBK" %>

<%
int i=0;
int Size=0;
String FileName="",FileExt="",suffix="",name1="",newname="",path="",Fnewname="";

String ftpHostname="127.0.0.1"; //ftp主机地址
String ftpUser="ftp-username"; //用户名
String ftpPwd="ftp-password"; //密码
String ftpDir="/"; //ftp目录

FTPClient ftp=new FTPClient();

mySmartUpload.initialize(pageContext);
mySmartUpload.upload();

com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);

if(!myFile.isMissing()) {
Size=myFile.getSize();
FileName=myFile.getFileName();
FileExt=myFile.getFileExt();
path=myFile.getFilePathName();
suffix=FileName.substring(0,FileName.lastIndexOf('.'));
if(Size>=300000) {
out.print(”\n”);
} else {
java.util.Date date = new java.util.Date();
SimpleDateFormat formatter1 = new SimpleDateFormat(”yyyyMMddhhmmsss”);
name1=FileName.substring(FileName.indexOf(”.”),FileName.length());
newname=formatter1.format(date)+name1;
myFile.saveAs(”/mms/manager/uploads_temp/” + newname); //利用smartupload上传到jsp服务器上的一个临时文件夹内,需要根据自己的环境进行设置。
}

try {
ftp.connect(ftpHostname);
ftp.login(ftpUser,ftpPwd);
ftp.changeWorkingDirectory(ftpDir);
ftp.setFileType(FTP.BINARY_FILE_TYPE); //以BINARY格式传送文件
Fnewname=”C:\\Tomcat\\webapps\\ROOT\\mms\\manager\\uploads_temp\\”+newname+”"; //这里需要给出的是文件所在本地机器的根目录路径,也就是myFile.saveAs的路径

FileInputStream f_in=new FileInputStream(Fnewname);
ftp.storeFile(newname,f_in); //存储文件到ftp的/file目录中。
f_in.close();
} catch(Exception e) {
e.printStackTrace();
}
//删除临时上传到程序所在服务器的文件,保证空间的合理利用。
String dir = “mms/manager/uploads_temp”; //需要根据目录的设置来修改
String s_direct = getServletConfig().getServletContext().getRealPath(dir);
java.io.File f = new java.io.File(”"+s_direct+”/”+newname+”");
f.delete();
}
%>

分类: 程序设计 标签:

Java获得汉字的首写字母

2009年7月25日 root 2 条评论


package cn.showtrue.tools;

public class Letters {
//字母Z使用了两个标签,这里有27个值
//i, u, v都不做声母, 跟随前面的字母
private static char[] chartable =
{
'啊', '芭', '擦', '搭', '蛾', '发', '噶', '哈', '哈',
'击', '喀', '垃', '妈', '拿', '哦', '啪', '期', '然',
'撒', '塌', '塌', '塌', '挖', '昔', '压', '匝', '座'
};

private static char[] alphatable =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};

private static int[] table = new int[27];

//主函数,输入字符,得到他的声母,
//英文字母返回对应的大写字母
//其他非简体汉字返回 '0'

public static char Char2Alpha(char ch){
if (ch >= 'a' && ch <= 'z')
return (char) (ch - 'a' + 'A');
if (ch >= 'A' && ch <= 'Z')
return ch;
int gb = gbValue(ch);
if (gb < table[0])
return '0';
int i;
for (i = 0; i < 26; ++i){
if (match(i, gb)) break;
}
if (i >= 26)
return '0';
else
return alphatable[i];
}

//根据一个包含汉字的字符串返回一个汉字拼音首字母的字符串
public static String getFirstLetter(String SourceStr){
for (int i = 0; i < 27; ++i) {
table[i] = gbValue(chartable[i]);
}
String Result = "";
int StrLength = SourceStr.length();
int i;
try{
for (i = 0; i < StrLength; i++){
Result += Char2Alpha(SourceStr.charAt(i));
}
} catch (Exception e){
Result = "";
}
return Result;
}

private static boolean match(int i, int gb){
if (gb < table[i])
return false;
int j = i + 1;
//字母Z使用了两个标签
while (j < 26 && (table[j] == table[i])) ++j;
if (j == 26)
return gb <= table[j];
else
return gb < table[j];
}

//取出汉字的编码
private static int gbValue(char ch){
String str = new String();
str += ch;
try{
byte[] bytes = str.getBytes("GB2312");
if (bytes.length < 2)
return 0;
return (bytes[0] << 8 & 0xff00) + (bytes[1] & 0xff);
} catch (Exception e){
return 0;
}
}

public static void main(String[] args){
System.out.println(Letters.getFirstLetter("简单"));
return;
}
}

经测试,对简体中文有效,繁体就会出问题。

分类: 程序设计 标签:

Oracle查询结果按指定顺序排序方法

2009年7月24日 root 没有评论

select id,g_name from shop_goods where id in(6895,6592,6589) order by DECODE(id,’6895′,’1′,’6592′,’2′,’6589′,’3′,id)

分类: 程序设计 标签:

execute、executeQuery和executeUpdate之间的区别

2009年6月26日 root 没有评论

JDBCTM中Statement接口提供的execute、executeQuery和executeUpdate之间的区别

Statement 接口提供了三种执行 SQL 语句的方法:executeQuery、executeUpdate 和 execute。使用哪一个方法由 SQL 语句所产生的内容决定。

方法executeQuery
用于产生单个结果集的语句,例如 SELECT 语句。 被使用最多的执行 SQL 语句的方法是 executeQuery。这个方法被用来执行 SELECT 语句,它几乎是使用最多的 SQL 语句。

方法executeUpdate
用于执行 INSERT、UPDATE 或 DELETE 语句以及 SQL DDL(数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。INSERT、UPDATE 或 DELETE 语句的效果是修改表中零行或多行中的一列或多列。executeUpdate 的返回值是一个整数,指示受影响的行数(即更新计数)。对于 CREATE TABLE 或 DROP TABLE 等不操作行的语句,executeUpdate 的返回值总为零。

使用executeUpdate方法是因为在 createTableCoffees 中的 SQL 语句是 DDL (数据定义语言)语句。创建表,改变表,删除表都是 DDL 语句的例子,要用 executeUpdate 方法来执行。你也可以从它的名字里看出,方法 executeUpdate 也被用于执行更新表 SQL 语句。实际上,相对于创建表来说,executeUpdate 用于更新表的时间更多,因为表只需要创建一次,但经常被更新。
方法execute:
用于执行返回多个结果集、多个更新计数或二者组合的语句。因为多数程序员不会需要该高级功能

execute方法应该仅在语句能返回多个ResultSet对象、多个更新计数或ResultSet对象与更新计数的组合时使用。当执行某个已存储过程 或动态执行未知 SQL 字符串(即应用程序程序员在编译时未知)时,有可能出现多个结果的情况,尽管这种情况很少见。
因为方法 execute 处理非常规情况,所以获取其结果需要一些特殊处理并不足为怪。例如,假定已知某个过程返回两个结果集,则在使用方法 execute 执行该过程后,必须调用方法 getResultSet 获得第一个结果集,然后调用适当的 getXXX 方法获取其中的值。要获得第二个结果集,需要先调用 getMoreResults 方法,然后再调用 getResultSet 方法。如果已知某个过程返回两个更新计数,则首先调用方法 getUpdateCount,然后调用 getMoreResults,并再次调用 getUpdateCount。
对于不知道返回内容,则情况更为复杂。如果结果是 ResultSet 对象,则方法 execute 返回 true;如果结果是 Java int,则返回 false。如果返回 int,则意味着结果是更新计数或执行的语句是 DDL 命令。在调用方法 execute 之后要做的第一件事情是调用 getResultSet 或 getUpdateCount。调用方法 getResultSet 可以获得两个或多个 ResultSet 对象中第一个对象;或调用方法 getUpdateCount 可以获得两个或多个更新计数中第一个更新计数的内容。
当 SQL 语句的结果不是结果集时,则方法 getResultSet 将返回 null。这可能意味着结果是一个更新计数或没有其它结果。在这种情况下,判断 null 真正含义的唯一方法是调用方法 getUpdateCount,它将返回一个整数。这个整数为调用语句所影响的行数;如果为 -1 则表示结果是结果集或没有结果。如果方法 getResultSet 已返回 null(表示结果不是 ResultSet 对象),则返回值 -1 表示没有其它结果。也就是说,当下列条件为真时表示没有结果(或没有其它结果):

((stmt.getResultSet() == null) && (stmt.getUpdateCount() == -1))

如果已经调用方法 getResultSet 并处理了它返回的 ResultSet 对象,则有必要调用方法 getMoreResults 以确定是否有其它结果集或更新计数。如果 getMoreResults 返回 true,则需要再次调用 getResultSet 来检索下一个结果集。如上所述,如果 getResultSet 返回 null,则需要调用 getUpdateCount 来检查 null 是表示结果为更新计数还是表示没有其它结果。

当 getMoreResults 返回 false 时,它表示该 SQL 语句返回一个更新计数或没有其它结果。因此需要调用方法 getUpdateCount 来检查它是哪一种情况。在这种情况下,当下列条件为真时表示没有其它结果:

((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))

下面的代码演示了一种方法用来确认已访问调用方法 execute 所产生的全部结果集和更新计数:
stmt.execute(queryStringWithUnknownResults);
while (true) {
int rowCount = stmt.getUpdateCount();
if (rowCount > 0) { // 它是更新计数
System.out.println(”Rows changed = ” + count);
stmt.getMoreResults();
continue;
}
if (rowCount == 0) { // DDL 命令或 0 个更新
System.out.println(” No rows changed or statement was DDL
command”);
stmt.getMoreResults();
continue;
}

// 执行到这里,证明有一个结果集
// 或没有其它结果

ResultSet rs = stmt.getResultSet;
if (rs != null) {
. . . // 使用元数据获得关于结果集列的信息
while (rs.next()) {
. . . // 处理结果
stmt.getMoreResults();
continue;
}
break; // 没有其它结果

分类: 程序设计 标签:

javascript获取和设置FCKeditor内容

2009年6月26日 root 没有评论

利用Javascript取和设FCKeditor值也是非常容易的,如下:

// 获取编辑器中HTML内容
function getEditorHTMLContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.GetXHTML(true));
}

// 获取编辑器中文字内容
function getEditorTextContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.EditorDocument.body.innerText);
}

// 设置编辑器中内容
function SetEditorContents(EditorName, ContentStr) {
var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
oEditor.SetHTML(ContentStr) ;
}

FCKeditorAPI是FCKeditor加载后注册的一个全局对象,利用它我们就可以完成对编辑器的各种操作。

在当前页获得 FCK 编辑器实例:
var Editor = FCKeditorAPI.GetInstance(’InstanceName’);

从 FCK 编辑器的弹出窗口中获得 FCK 编辑器实例:
var Editor = window.parent.InnerDialogLoaded().FCK;

从框架页面的子框架中获得其它子框架的 FCK 编辑器实例:
var Editor = window.FrameName.FCKeditorAPI.GetInstance(’InstanceName’);

从页面弹出窗口中获得父窗口的 FCK 编辑器实例:
var Editor = opener.FCKeditorAPI.GetInstance(’InstanceName’);

获得 FCK 编辑器的内容:
oEditor.GetXHTML(formatted); // formatted 为:true|false,表示是否按HTML格式取出
也可用:
oEditor.GetXHTML();

设置 FCK 编辑器的内容:
oEditor.SetHTML(”content”, false); // 第二个参数为:true|false,是否以所见即所得方式设置其内容。此方法常用于”设置初始值”或”表单重置”哦作。

插入内容到 FCK 编辑器:
oEditor.InsertHtml(”html”); // “html”为HTML文本

检查 FCK 编辑器内容是否发生变化:
oEditor.IsDirty();

在 FCK 编辑器之外调用 FCK 编辑器工具条命令:
命令列表如下:
DocProps, Templates, Link, Unlink, Anchor, BulletedList, NumberedList, About, Find, Replace, Image, Flash, SpecialChar, Smiley, Table, TableProp, TableCellProp, UniversalKey, Style, FontName, FontSize, FontFormat, Source, Preview, Save, NewPage, PageBreak, TextColor, BGColor, PasteText, PasteWord, TableInsertRow, TableDeleteRows, TableInsertColumn, TableDeleteColumns, TableInsertCell, TableDeleteCells, TableMergeCells, TableSplitCell, TableDelete, Form, Checkbox, Radio, TextField, Textarea, HiddenField, Button, Select, ImageButton, SpellCheck, FitWindow, Undo, Redo

使用方法如下:
oEditor.Commands.GetCommand(’FitWindow’).Execute();

= FCKConfig.BasePath + ‘plugins/’
// FCKConfig.Plugins.Add( ‘placeholder’, ‘en,it’ ) ;


去掉//后,就相当于把placeholder这个插件功能加上了,fckeditor的插件文件都在/editor/plugins/文件夹下分类按文 件夹放置的,对于fckeditor2.0来说,里面有两个文件夹,也就是有两个官方插件,placeholder这个文件夹就是我们刚才加上去的,主要 用于多参数或单参数自定义标签的匹配,这个在制作编辑模板时非常管用,要想看具体实例的话,大家可以去下载acms 这个系统查看学习,另一个文件夹tablecommands就是编辑器里的表格编辑用到的了。当然,如果你想制作自己其它用途的插件,那就只要按照 fckeidtor插件的制作规则制作完放置在/editor/plugins/下就行,然后再在fckeidtor.js里再添加 FCKConfig.Plugins.Add(’Plugin Name’,',lang,lang’);就可以了。

第二部分 ,如何让编辑器一打开的时候,编辑工具条不出现,等点“展开工具栏”时才出现?Easy,FCKeditor本身提供了这个功能啦,打开fckconfig.js,找到

FCKConfig.ToolbarStartExpanded = true ;
改成
FCKConfig.ToolbarStartExpanded = false ;
就可以啦!

第三部分,使用自己的表情图标,同样打开fckcofnig.js到最底部那一段
FCKConfig.SmileyPath = FCKConfig.BasePath + ‘images/smiley/msn/’ ;
FCKConfig.SmileyImages = ['regular_smile.gif','sad_smile.gif','wink_smile.gif'] ;
FCKConfig.SmileyColumns = 8 ;
FCKConfig.SmileyWindowWidth = 320 ;
FCKConfig.SmileyWindowHeight = 240 ;

上面这段已经是我修改过的了,为了我发表此文的版面不会被撑得太开,我把FCKConfig.SmileyImages那一行改得只有三个表情图了。

第一行,当然是表情图标路径的设置,第二行是相关表情图标文件名的一个List,第三行是指弹出的表情添加窗口最每行的表情数,下面两个参数是弹出的模态窗口的宽和高喽。

第四部分,文件上传管理部分

此部分可能是大家最为关心的,上一篇文章简单的讲了如何修改来上传文件以及使用fckeidtor2.0才提供的快速上传功能。再我们继续再深层次的讲解上传功能

FCKConfig.LinkBrowser = true ;
FCKConfig.ImageBrowser = true ;
FCKConfig.FlashBrowser = true ;在fckconfig.js找到这三句,这三句不是连着的哦,只是我把他们集中到这儿来了,设置为true的意思就是允许使用fckeditor来浏览 服务器端的文件图像以及flash等,这个功能是你插入图片时弹出的窗口上那个“浏览服务器”按钮可以体现出来,如果你的编辑器只用来自己用或是只在后台 管理用,这个功能无疑很好用,因为他让你很直观地对服务器的文件进行上传操作。但是如果你的系统要面向前台用户或是像blog这样的系统要用的话,这个安 全隐患可就大了哦。于是我们把其一律设置为false;如下

FCKConfig.LinkBrowser = false ;
FCKConfig.ImageBrowser = false ;
FCKConfig.FlashBrowser = false ;

这样一来,我们就只有快速上传可用了啊,好!接下来就来修改,同样以asp为范例进行,进入/editor/filemanager/upload/asp/打开config.asp,修改
ConfigUserFilesPath = “/UserFiles/”这个设置是上传文件的总目录,我这里就不动了,你想改自己改了

好,再打开此目录下的upload.asp文件,找到下面这一段
Dim resourceType
If ( Request.QueryString(”Type”) <> “” ) Then
resourceType = Request.QueryString(”Type”)
Else
resourceType = “File”
End If
然后再在其后面添加
ConfigUserFilesPath = ConfigUserFilesPath & resourceType &”/”& Year(Date()) &”/”& Month(Date()) &”/”
这样的话,上传的文件就进入“/userfiles/文件类型(如image或file或flash)/年/月/”这样的文件夹下了,这个设置对单用户来用已经足够了,如果你想给多用户系统用,那就这样来改
ConfigUserFilesPath = ConfigUserFilesPath & Session(”username”) & resourceType &”/”& Year(Date()) &”/”& Month(Date()) &”/”
这样上传的文件就进入“/userfiles/用户目录/文件类型/年/月/”下了,当然如果你不想这么安排也可以修改成别的,比如说用户目录再深一层等,这里的Session(”username”)请根据自己的需要进行修改或换掉。

上传的目录设置完了,但是上传程序还不会自己创建这些文件夹,如果不存在的话,上传不会成功的,那么我们就得根据上面的上传路径的要求进行递归来生成目录了。

找到这一段
Dim sServerDir
sServerDir = Server.MapPath( ConfigUserFilesPath )
If ( Right( sServerDir, 1 ) <> “\” ) Then
sServerDir = sServerDir & “\”
End If

把它下面的这两行
Dim oFSO
Set oFSO = Server.CreateObject( “Scripting.FileSystemObject” )
用下面这一段代码来替换
dim arrPath,strTmpPath,intRow
strTmpPath = “”
arrPath = Split(sServerDir, “\”)
Dim oFSO
Set oFSO = Server.CreateObject( “Scripting.FileSystemObject” )
for intRow = 0 to Ubound(arrPath)
strTmpPath = strTmpPath & arrPath(intRow) & “\”
if oFSO.folderExists(strTmpPath)=false then
oFSO.CreateFolder(strTmpPath)
end if
next
用这段代码就可以生成你想要的文件夹了,在上传的时候自动生成。

好了,上传文件的修改到现在可以暂时告一段落了,但是,对于中文用户还存在这么个问题,就是fckeditor的文件上传默认是不改名的,同时还不 支持中文文件名,这样一来是上传的文件会变成“.jpg”这样的无法读的文件,再就是会有重名文件,当然重名这点倒没什么,因为fckeditor会自动 改名,会在文件名后加(1)这样来进行标识。但是,我们通常的习惯是让程序自动生成不重复的文件名

在刚才那一段代码的下面紧接着就是
‘ Get the uploaded file name.
sFileName = oUploader.File( “NewFile” ).Name
看清楚了,这个就是文件名啦,我们来把它改掉,当然得有个生成文件名的函数才行,改成下面这样

‘//取得一个不重复的序号
Public Function GetNewID()
dim ranNum
dim dtNow
randomize
dtNow=Now()
ranNum=int(90000*rnd)+10000
GetNewID=year(dtNow) & right(”0″ & month(dtNow),2) & right(”0″ & day(dtNow),2) & right(”0″ & hour(dtNow),2) & right(”0″ & minute(dtNow),2) & right(”0″ & second(dtNow),2) & ranNum
End Function

‘ Get the uploaded file name.
sFileName = GetNewID() &”.”& split(oUploader.File( “NewFile” ).Name,”.”)(1)

上传的文件就自动改名生成如20050802122536365.jpg这样的文件名了,是由年月日时分秒以及三位随机数组成的文件名了

=====================================

FCKeditor加载完成后做处理的方法

function FCKeditor_OnComplete( editorInstance )
{
editorInstance.Events.AttachEvent( ‘OnBlur’ , FCKeditor_OnBlur ) ;
editorInstance.Events.AttachEvent( ‘OnFocus’, FCKeditor_OnFocus ) ;
}

function FCKeditor_OnBlur( editorInstance )
{
editorInstance.ToolbarSet.Collapse() ;
}

function FCKeditor_OnFocus( editorInstance )
{
editorInstance.ToolbarSet.Expand() ;
}

分类: 程序设计 标签:

FCKeditor 2.4.1 Java压缩版(上传图片自动重命名)

2009年6月22日 root 没有评论

使用FCKeditor java版本的演示程序的时候上传文件名不自动重新命名,如果是中文的话会出现一点小问题。于是从网上搜索自动重新命名的版本,始终没找到!无奈自己编译了下原文件,把设置成了文件上传后重新自动命名。文件名是根据当时时间命名,用的是Data 的getTime()方法!
改变文件默认上传路径是修改fckeditor.properties 添加默认上传路径和上传文件类型的定义。fckeditor.properties的修改参照net.fckeditor.handlers.default.properties文件中的定义修改,fckeditor.properties的配置优先级别高于default.properties中的设置。default.properties中的默认配置如:

#
# FCKeditor – The text editor for Internet – http://www.fckeditor.net
# Copyright (C) 2003-2008 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# – GNU General Public License Version 2 or later (the “GPL”)
# http://www.gnu.org/licenses/gpl.html
#
# – GNU Lesser General Public License Version 2.1 or later (the “LGPL”)
# http://www.gnu.org/licenses/lgpl.html
#
# – Mozilla Public License Version 1.1 or later (the “MPL”)
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# Default properties for FCKeditor.Java
#
# @version $Id: default.properties 1632 2008-02-25 18:11:06Z th-schwarz $

# default allowed extensions settings
connector.resourceType.file.extensions.allowed = 7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip
connector.resourceType.image.extensions.allowed = bmp|gif|jpeg|jpg|png
connector.resourceType.flash.extensions.allowed = swf|fla
connector.resourceType.media.extensions.allowed = aiff|asf|avi|bmp|fla|flv|gif|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|png|qt|ram|rm|rmi|rmvb|swf|tif|tiff|wav|wma|wmv

# default resource type paths
connector.resourceType.file.path = /file
connector.resourceType.image.path = /image
connector.resourceType.flash.path = /flash
connector.resourceType.media.path = /media

# Due to security issues with Apache modules, it is recommended to leave this
# setting enabled.
connector.forceSingleExtension = true

# base directory for the user files relative to the context root
connector.userFilesPath = /userfiles

# Instructs the Connector to return the full URL of a file/folder in the XML
# response rather than the absolute URL
connector.fullUrl = false

# Instructs the Connector to check, if the uploaded image is really one
connector.secureImageUploads = true

# directory of the editor relative to the context root
fckeditor.basePath = /fckeditor

# default height of the editor
fckeditor.height = 200

# default toolbar set of the editor
fckeditor.toolbarSet = Default

# default width of the editor
fckeditor.width = 100%

# some messages
message.enabled_tag.compatible_browser.no = Your browser is not compatible
message.enabled_tag.compatible_browser.yes = Your browser is fully compatible
message.enabled_tag.connector.file_browsing.disabled = The Connector is disabled for FileBrowsing
message.enabled_tag.connector.file_browsing.enabled = The Connector is enabled for FileBrowsing
message.enabled_tag.connector.file_upload.disabled = The Connector is disabled for FileUpload
message.enabled_tag.connector.file_upload.enabled = The Connector is enabled for FileUpload

文件默认上传路径修改:connector.userFilesPath = /userfiles

上传文件自动重命名(含精简了的编辑器):fckeditor 2.4.1

FCKeditor 2.4.1 演示程序下载:http://www.6tbl.com/post/155/

jassistant 1.06 JDBDevelop Assistant数据库生成java程序

2009年6月22日 root 没有评论

The assistant is a class and a package browser. It is divided into two parts: the main class browser and the package viewer. A third options window may be opened to control the program behavior. The main goal of this program is to be able to find very quickly a class, its source, its methods, fields, constructors… and to be able to explore the packages. Completion, and class homonyms may be enabled. Concerning the package viewer, well, you have the package hierarchy and the class hierarchy inside a selected package, which is the inheritance hierarchy inside a package. The classes which appear with an icon marked “i” are interface classes and the ones with an “a” are abstract classes. The options window allows to put filters for the lists which are given: definition with long or short names, filter on the scope (public, package, protected, private), filter on the modifiers (native, abstract, static…), the order for the search of the sources (java, jj, decompile or disassemble), sorting options and an uptdate package button to reread all your packages. The assistant was swing free. At the beginning I was happy to use swing, which is very nice, and that’s why I have a swing package too. But as time passed I saw that swing had bugs and that it was not usable in a real program because it is too slow! This is the reason why I have my own tree classes in pure AWT java! It seems now that swing has been improved, specially 1.1.1, so… I came back to it for the code viewer. This explains that the code is in majority pure AWT, and the viewer in Swing.
assist

绿色版本下载:jassistant(RAR)

分类: 程序设计 标签:

Tomcat url地址转换urlrewritefilter-3.2.0

2009年6月20日 root 没有评论

web.xml中添加方法:

1
2
3
4
5
6
7
8
9
10
11
12
    <filter>
      <filter-name>UrlRewriteFilter</filter-name>
      <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
      <init-param>
	   <param-name>confPath</param-name>
	   <param-value>/WEB-INF/config/urlrewrite.xml </param-value>
	  </init-param>
    </filter>
    <filter-mapping>
      <filter-name>UrlRewriteFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

urlrewrite.xml 示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
 
<!--
 
    Configuration file for UrlRewriteFilter
    http://tuckey.org/urlrewrite/
 
-->
<urlrewrite>
 
    <rule>
        <note>
            The rule means that requests to /test/status/ will be redirected to /rewrite-status
            the url will be rewritten.
        </note>
        <from>/test/status/</from>
        <to type="redirect">%{context-path}/rewrite-status</to>
    </rule>
 
 
    <outbound-rule>
        <note>
            The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
            the url /rewrite-status will be rewritten to /test/status/.
 
            The above rule and this outbound-rule means that end users should never see the
            url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
            in your pages.
        </note>
        <from>/rewrite-status</from>
        <to>/test/status/</to>
    </outbound-rule>
 
 
    <!--
 
    INSTALLATION
 
        in your web.xml add...
 
        <filter>
            <filter-name>UrlRewriteFilter</filter-name>
            <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
            <init-param>
                <param-name>logLevel</param-name>
                <param-value>WARN</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>UrlRewriteFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
 
     EXAMPLES
 
     Redirect one url
        <rule>
            <from>/some/old/page.html</from>
            <to type="redirect">/very/new/page.html</to>
        </rule>
 
    Redirect a directory
        <rule>
            <from>/some/olddir/(.*)</from>
            <to type="redirect">/very/newdir/$1</to>
        </rule>
 
    Clean a url
        <rule>
            <from>/products/([0-9]+)</from>
            <to>/products/index.jsp?product_id=$1</to>
        </rule>
    eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.
 
    Browser detection
        <rule>
            <condition name="user-agent">Mozilla/[1-4]</condition>
            <from>/some/page.html</from>
            <to>/some/page-for-old-browsers.html</to>
        </rule>
    eg, will pass the request for /some/page.html on to /some/page-for-old-browsers.html only for older
    browsers whose user agent srtings match Mozilla/1, Mozilla/2, Mozilla/3 or Mozilla/4.
 
    Centralised browser detection
        <rule>
            <condition name="user-agent">Mozilla/[1-4]</condition>
            <set type="request" name="browser">moz</set>
        </rule>
    eg, all requests will be checked against the condition and if matched
    request.setAttribute("browser", "moz") will be called.
 
    -->
 
</urlrewrite>

下载:urlrewritefilter-3.2.0

ECshop中广告代码优化-本地连接不统计。

2009年6月12日 root 没有评论

ECshop中插入的广告都是今天过统计的,但是对于站内的广告很多是不需要这样操作的,并且这样页面上连接不是直接连接的内页,是不是对SEO有一定的影响,具体没太深入了解。下面是我自己对ECShop的一点修改,程序修改成了判断连接是不是以http开头,如果是以http开头那就统计这个广告的点击,如果不是则不统计。这样在后台添加光的时候如果想让统计则加上http://如果不需要则直写站内地址即可。(这个只针对与站内的地址,比如专题活动等。)
/includes/lib_insert.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
        switch ($row['media_type'])
        {
            case 0: // 图片广告
                $src = (strpos($row['ad_code'], 'http://') === false && strpos($row['ad_code'], 'https://') === false) ?
                        DATA_DIR . "/afficheimg/$row[ad_code]" : $row['ad_code'];
				if(strpos($row['ad_link'], 'http://')===false){
					$ads[] = "<a href='" . $row["ad_link"]. "'
					target='_blank'><img src='$src' width='" .$row['ad_width']. "' height='$row[ad_height]'
					border='0' /></a>";
				}else{
					$ads[] = "<a href='affiche.php?ad_id=$row[ad_id]&amp;uri=" . urlencode($row["ad_link"]). "'
					target='_blank'><img src='$src' width='" .$row['ad_width']. "' height='$row[ad_height]'
                	border='0' /></a>";
				}
                //$ads[] = "<a href='affiche.php?ad_id=$row[ad_id]&amp;uri=" . urlencode($row["ad_link"]). "'
                //target='_blank'><img src='$src' width='" .$row['ad_width']. "' height='$row[ad_height]'
                //border='0' /></a>";
                break;
            case 1: // Flash
                $src = (strpos($row['ad_code'], 'http://') === false && strpos($row['ad_code'], 'https://') === false) ?
                        DATA_DIR . "/afficheimg/$row[ad_code]" : $row['ad_code'];
                $ads[] = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " .
                         "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\"  " .
                           "width='$row[ad_width]' height='$row[ad_height]'>
                           <param name='movie' value='$src'>
                           <param name='quality' value='high'>
                           <embed src='$src' quality='high'
                           pluginspage='http://www.macromedia.com/go/getflashplayer'
                           type='application/x-shockwave-flash' width='$row[ad_width]'
                           height='$row[ad_height]'></embed>
                         </object>";
                break;
            case 2: // CODE
                $ads[] = $row['ad_code'];
                break;
            case 3: // TEXT
				if(strpos($row['ad_link'], 'http://')===false){
					$ads[] = "<a href='" . $row["ad_link"]. "' target='_blank'>" .htmlspecialchars($row['ad_code']). '</a>';
				}else{
					$ads[] = "<a href='affiche.php?ad_id=$row[ad_id]&amp;uri=" . urlencode($row["ad_link"]) .
					"' target='_blank'>" .htmlspecialchars($row['ad_code']). '</a>';
				}
                //$ads[] = "<a href='affiche.php?ad_id=$row[ad_id]&amp;uri=" .urlencode($row["ad_link"]). "'
                //target='_blank'>" .htmlspecialchars($row['ad_code']). '</a>';
                break;
        }
分类: 程序设计 标签:

JSP中include文件的编码问题

2009年6月2日 root 没有评论

今天做程序,在一个原来的程序基础上添加修改。程序开始运行没问题,添加一个页面后显示错误,提示信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
HTTP Status 500 -
 
type Exception report
 
message
 
description The server encountered an internal error () that prevented it from fulfilling this request.
 
exception
 
org.apache.jasper.JasperException: /root/menu/../check.jsp(1,1) Page directive: illegal to have multiple occurrences of contentType with different values (old: text/html; charset=UTF-8, new: text/html; charset=utf-8)
	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
	org.apache.jasper.compiler.Validator$DirectiveVisitor.visit(Validator.java:133)
	org.apache.jasper.compiler.Node$PageDirective.accept(Node.java:590)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
	org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
	org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
	org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
	org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
	org.apache.jasper.compiler.Validator$DirectiveVisitor.visit(Validator.java:100)
	org.apache.jasper.compiler.Node$IncludeDirective.accept(Node.java:638)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
	org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
	org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
	org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
	org.apache.jasper.compiler.Validator.validate(Validator.java:1702)
	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:166)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:315)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
Apache Tomcat/6.0.18

根据错误提示:/root/menu/../check.jsp(1,1) Page directive: illegal to have multiple occurrences of contentType with different values (old: text/html; charset=UTF-8, new: text/html; charset=utf-8),应该是UTF-8大小写的区别,这里到底是应该用大写还是小写呢?经尝试发现,只要引入文件和被引入文件的大小写一致,就没问题,要么都是utf-8,要么都是UTF-8,如果两个文件指定编码的大小写不一致,就会报错。而无论是统一使用大写还是小写,在程序中设置接受中文参数编码的函数:request.setCharacterEncoding(”UTF-8″); 中使用大写或者小写均可以,都会正常接受数据。
在网上搜索了下关于jsp的include文件编码问题,发下下面文章,更清晰了一些。

解决方法:
1.
问题描述:<%@ include file="*.html" %> 的中文乱码问题

要解决这个问题,当然最简单的就是在每个被 include 的文件第一行,加上

<%@ page contentType="text/html;charset=gb2312" %>
这样一定可以确保中文 jsp 档不会出现乱码,只不过,一旦程序修改成这样的模式,这种程序就无法在旧的
jsp/servlet container 上执行了,因为旧的规格是不允被 include 档案中再出现 <%@ page ... %> 这样的定义的。

况且,就算你愿意为了 Tomcat 5.0.x 特别维护一套不同版本的 Source Code,你会遇到重大的挫折,因为 Tomcat 5.0.x 版在 charset 的设定上,会特别检查include 别人的程序与被人include 的程序,这二个程序中所定义的 charset 是不是一样,如果不一样,在编译时就会产生错误。更恐怖的是,竟然还分大小写,比如说:”gb2312″ “GB2312″ 这样的定义,在 Tomcat 的认定上是不同的。

更好的解决方案
在 Tomcat 5.0.x 中,Tomcat 支持了 JSP 2.0 的规格,同时也支持了部分 J2EE 1.4 的规格,在 J2EE 1.4 的规格中,有关 JSP 的部份,有一个 的 XML Tag,这个 XML 区块用来定义与 JSP 相关的特殊属性,包含采用的 taglib 与 以下说明的 ,而解决 include 档中文问题的方法就定义在 中。

在当前应用系统的web.xml里加入jsp-config代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<jsp-config>
    <jsp-property-group>
        <description>
            Special property group for JSP Configuration JSP example.
        </description>
        <display-name>JSPConfiguration</display-name>
        <url-pattern>*.jsp</url-pattern>
        <el-ignored>true</el-ignored>
        <page-encoding>GB2312</page-encoding>
        <scripting-invalid>false</scripting-invalid>
        <include-prelude></include-prelude>
        <include-coda></include-coda>
 
  <description>
            Special property group for JSP Configuration JSP example.
        </description>
        <display-name>JSPConfiguration</display-name>
        <url-pattern>*.html</url-pattern>
        <el-ignored>true</el-ignored>
        <page-encoding>GB2312</page-encoding>
        <scripting-invalid>false</scripting-invalid>
        <include-prelude></include-prelude>
        <include-coda></include-coda>
    </jsp-property-group>
</jsp-config>
 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
 
... ...
 
</webapp>

说明:里的定义,就是通知当前应用服务器,当前应用系统下,所有的 .jsp, .html 文件,若是没有定义contentType=”text/html;charset=gb2312″ 时,就会采用预设的 “GB2312″ 字符集去处理,如此,就不须要在每个 include 的档案第一行加上 contentType=”text/html;charset=gb2312″ 了。

注:

<jsp-config>标签使用详解

包括 两个子元素。

其中元素在JSP 1.2时就已经存在;而是JSP 2.0 新增的元素。
元素主要有八个子元素,它们分别为:

1.:设定的说明;
2.:设定名称;
3.:设定值所影响的范围,如:/CH2 或 /*.jsp;
4.:若为true,表示不支持EL 语法;
5.:若为true,表示不支持<% scripting %>语法;
6. :设定JSP 网页的编码;
7.:设置JSP 网页的抬头,扩展名为.jspf;
8.:设置JSP 网页的结尾,扩展名为.jspf。

tomcat 5中include页面乱码问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
 
<jsp-config>
<jsp-property-group>
<description>Special property group for JSP Configuration JSP example.</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GBK</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
 
<description>Special property group for JSP Configuration JSP example.</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GBK</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
</jsp-property-group>
</jsp-config>

2.关于中文出现乱码的解决办法
在一个编码为utf-8的页面中,使用包含另一个.jsp/.html文件时,被包含的页面单独浏览正常,但被包含后就会遇到乱码问题。解决的办法是,在每个被包含的页面开始加上下面一行<% page contentType="text/html;charset=utf-8" %>这个方法可以解决jsp include jsp的中文乱码问题。也就是说,被包含的页面必须改成.jsp,哪怕它的内容只有静态html,否则的话还是会出现乱码,如何解决include .html文件中文乱码的问题,还在寻找中。

具体搜索到的文章中的设置没有去tomcat的设置里面去查找,但是明确了一点jsp中include文件的编码格式不仅仅需要一致,大小写也不能错(搜索到的文章中说是tomcat5以后的版本才区分的,暂且不管了)。
还有一点,是刚开始接触jsp开发的时候,总是出现编码乱码的问题,现在已经基本全都解决了,再没有遇到什么问题。归结下,除了tomcat和数据库要做好统一的编码外,程序也要统一编码使用。

分类: 程序设计 标签: ,