- 浏览: 41830 次
- 性别:
- 来自: 广州
最新评论
-
love2008:
...
jsf之三方组件包myfaces之tree2动态应用 -
vwangxin:
fangbiao23 2007-10-16 ,太感谢了
fckeditor 编辑器(中文乱码已修改) -
vwangxin:
fangbiao23 2007-10-16 ,太感谢了
fckeditor 编辑器(中文乱码已修改) -
wtslh:
原来你的帖子中已经有答案了,不好意思。因为我jsp页面的编码都 ...
fckeditor 编辑器(中文乱码已修改) -
wtslh:
我不想把上传的中文名改成别的名字,否则在浏览图片的时候,就看不 ...
fckeditor 编辑器(中文乱码已修改)
一、fckeditor 基本解决中文乱码和可运行的更改程序可参考fangbiao23.iteye.com/admin/show/130831
二、fckeditor在jsf中使用的一些相关设置和修改
web.xml
xml 代码
- <!-- 在线编辑 -->
- <servlet>
- <servlet-name>Connector</servlet-name>
- <servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
- <init-param>
- <param-name>baseDir</param-name>
- <param-value>/EpFbUserFiles/</param-value>
- </init-param>
- <init-param>
- <param-name>debug</param-name>
- <param-value>true</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet>
- <servlet-name>SimpleUploader</servlet-name>
- <servlet-class>com.fredck.FCKeditor.uploader.SimpleUploaderServlet</servlet-class>
- <init-param>
- <param-name>baseDir</param-name>
- <param-value>/EpFbUserFiles/</param-value>
- </init-param>
- <init-param>
- <param-name>debug</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
- <param-name>enabled</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
- <param-name>AllowedFileSize</param-name>
- <param-value>5242880</param-value>
- </init-param>
- <init-param>
- <param-name>AllowedExtensionsFile</param-name>
- <param-value></param-value>
- </init-param>
- <init-param>
- <param-name>DeniedExtensionsFile</param-name>
- <param-value>php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi</param-value>
- </init-param>
- <init-param>
- <param-name>AllowedImageSize</param-name>
- <param-value>5242880</param-value>
- </init-param>
- <init-param>
- <param-name>AllowedExtensionsImage</param-name>
- <param-value>jpg|gif|jpeg|pjpeg|png|bmp</param-value>
- </init-param>
- <init-param>
- <param-name>DeniedExtensionsImage</param-name>
- <param-value></param-value>
- </init-param>
- <init-param>
- <param-name>AllowedFlashSize</param-name>
- <param-value>5242880</param-value>
- </init-param>
- <init-param>
- <param-name>AllowedExtensionsFlash</param-name>
- <param-value>swf|fla</param-value>
- </init-param>
- <init-param>
- <param-name>DeniedExtensionsFlash</param-name>
- <param-value></param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
xml 代码
- <servlet>
- <servlet-name>fckEitorUploadServlet</servlet-name>
- <servlet-class>ep.jsf.upload.FckEitorUploadServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>fckEitorUploadServlet</servlet-name>
- <url-pattern>/fckEitorUploadServlet</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>Connector</servlet-name>
- <url-pattern>/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>SimpleUploader</servlet-name>
- <url-pattern>/FCKeditor/editor/filemanager/upload/simpleuploader</url-pattern>
- </servlet-mapping>
upload.jsf
java 代码
- <script type="text/javascript">
- function FCKeditor_OnComplete( editorInstance )
- {
- editorInstance.Events.AttachEvent( 'OnBlur', onEditorBlur );
- }
- function onEditorBlur(){
- var msgPath = '';
- var imgMsg = '';
- var imgs = FCKeditorAPI.GetInstance('EditorDefault').EditorDocument.body.all.tags("img");
- var j =0;
- for(var i=0; i < imgs.length; i++){
- imgMsg = imgs[i].src;
- imgMsg = imgMsg.substring(imgMsg.indexOf('eppj')-1);
- if(imgMsg.indexOf('msn') == -1){
- if(j==0)
- msgPath = imgMsg;
- else
- msgPath = msgPath + '|'+ imgMsg;
- j++;
- }
- }
- document.getElementById('fckEditorForm:inputContent').value = FCKeditorAPI.GetInstance('EditorDefault').EditorDocument.body.innerHTML;
- }
- </script>
- <h:panelGroup>
- <h:outputLabel for="inputContent" value="资讯内容"/>
- <f:verbatim>
- <FCK:editor id="EditorDefault" basePath="/eppj/FCKeditor/"
- skinPath="/eppj/FCKeditor/editor/skins/office2003/"
- toolbarSet="Usable"
- imageBrowserURL="/eppj/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector"
- linkBrowserURL="/eppj/FCKeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector"
- flashBrowserURL="/eppj/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector"
- imageUploadURL="/eppj/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Image"
- linkUploadURL="/eppj/FCKeditor/editor/filemanager/upload/simpleuploader?Type=File"
- flashUploadURL="/eppj/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Flash"
- width="80%"
- height="450">
- </FCK:editor>
- </f:verbatim>
- <h:message for="inputContent"/>
- </h:panelGroup>
- <h:inputHidden id="inputContent" value="#{tradeBackManager.tdp.tradeContent}"> </h:inputHidden>
editor.jsf
java 代码
- <h:panelGroup>
- <h:outputLabel for="inputContent" value="资讯内容"/>
- <f:verbatim>
- <FCK:editor id="EditorDefault" basePath="/eppj/FCKeditor/"
- skinPath="/eppj/FCKeditor/editor/skins/office2003/"
- toolbarSet="Usable"
- imageBrowserURL="/eppj/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector"
- linkBrowserURL="/eppj/FCKeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector"
- flashBrowserURL="/eppj/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector"
- imageUploadURL="/eppj/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Image"
- linkUploadURL="/eppj/FCKeditor/editor/filemanager/upload/simpleuploader?Type=File"
- flashUploadURL="/eppj/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Flash"
- width="80%"
- height="450" >
- <%
- FacesContext fcg = FacesContext.getCurrentInstance();
- DtTradeBackManager dtfl = (DtTradeBackManager) fcg.getApplication().getVariableResolver().resolveVariable(fcg, "tradeBackManager");
- out.print(dtfl.getTdp().getTradeContent());
- %>
- </FCK:editor>
- </f:verbatim>
- <h:message for="inputContent"/>
- </h:panelGroup>
- <h:inputText id="inputContent" value="#{tradeBackManager.tdp.tradeContent}"> </h:inputText>
评论
4 楼
fangbiao23
2007-10-25
是的!!那個是可以用的,不過我沒用,聽說他有一些bug!在使用他時需要做一番修改!
3 楼
mygol
2007-10-24
有个fck-faces可以作jsf应用,不过它是基于myfaces的,不知道有没有高人可以改成基于jsf-ri
2 楼
fangbiao23
2007-10-19
以上提供的只是个人经验所得,仅供参考
1 楼
fangbiao23
2007-10-19
文件上传SimpleuploadServlet.java
支持文件大小控制
/*
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: SimpleUploaderServlet.java
* Java File Uploader class.
*
* Version: 2.3
* Modified: 2005-08-11 16:29:00
*
* File Authors:
* Simone Chiaretta (simo@users.sourceforge.net)
*/
package com.fredck.FCKeditor.uploader;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import org.apache.commons.fileupload.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
/**
* Servlet to upload files.<br>
*
* This servlet accepts just file uploads, eventually with a parameter specifying file type
*
* @author Simone Chiaretta (simo@users.sourceforge.net)
*/
public class SimpleUploaderServlet extends HttpServlet {
private static String baseDir;
private static boolean debug=false;
private static boolean enabled=false;
private static Hashtable allowedExtensions;
private static Hashtable deniedExtensions;
private static Hashtable allowedSize;//限制文件大小
private static String retVal="0";
private static long typeAllowedSize;
private static Logger log = Logger.getLogger(SimpleUploaderServlet.class);
/**
* Initialize the servlet.<br>
* Retrieve from the servlet configuration the "baseDir" which is the root of the file repository:<br>
* If not specified the value of "/UserFiles/" will be used.<br>
* Also it retrieve all allowed and denied extensions to be handled.
*
*/
public void init() throws ServletException {
debug=(new Boolean(getInitParameter("debug"))).booleanValue();
if(debug) System.out.println("\r\n---- SimpleUploaderServlet initialization started ----");
baseDir=getInitParameter("baseDir");
enabled=(new Boolean(getInitParameter("enabled"))).booleanValue();
if(baseDir==null)
baseDir="/EpUserFiles/";
String realBaseDir=getServletContext().getRealPath(baseDir);
File baseFile=new File(realBaseDir);
if(!baseFile.exists()){
baseFile.mkdir();
}
allowedExtensions = new Hashtable(3);
deniedExtensions = new Hashtable(3);
allowedSize = new Hashtable(3);
allowedExtensions.put("File",stringToArrayList(getInitParameter("AllowedExtensionsFile")));
deniedExtensions.put("File",stringToArrayList(getInitParameter("DeniedExtensionsFile")));
allowedSize.put("File", new Long(getInitParameter("AllowedFileSize")).longValue());
allowedExtensions.put("Image",stringToArrayList(getInitParameter("AllowedExtensionsImage")));
deniedExtensions.put("Image",stringToArrayList(getInitParameter("DeniedExtensionsImage")));
allowedSize.put("Image", new Long(getInitParameter("AllowedImageSize")).longValue());
allowedExtensions.put("Flash",stringToArrayList(getInitParameter("AllowedExtensionsFlash")));
deniedExtensions.put("Flash",stringToArrayList(getInitParameter("DeniedExtensionsFlash")));
allowedSize.put("Flash", new Long(getInitParameter("AllowedFlashSize")).longValue());
if(debug) System.out.println("---- SimpleUploaderServlet initialization completed ----\r\n");
}
/**
* Manage the Upload requests.<br>
*
* The servlet accepts commands sent in the following format:<br>
* simpleUploader?Type=ResourceType<br><br>
* It store the file (renaming it in case a file with the same name exists) and then return an HTML file
* with a javascript command in it.
*
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (debug) System.out.println("--- BEGIN DOPOST ---");
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Cache-Control","no-cache");
PrintWriter out = response.getWriter();
String typeStr=request.getParameter("Type");
String currentPath=baseDir+typeStr;
//在此为每个能上传图片的用片增加一个user目录,利用session来做
currentPath = currentPath+"/userName/";
String currentDirPath=getServletContext().getRealPath(currentPath);
currentPath=request.getContextPath()+currentPath;
File addUserNameFile=new File(currentDirPath);
if(!addUserNameFile.exists()){
addUserNameFile.mkdirs();
}
if (debug) System.out.println(currentDirPath);
String newName="";
String fileUrl="";
String errorMessage="";
if(enabled) {
DiskFileUpload upload = new DiskFileUpload();
upload.setHeaderEncoding("utf-8");
try {
List items = upload.parseRequest(request);
Map fields=new HashMap();
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField())
fields.put(item.getFieldName(),item.getString());
else
fields.put(item.getFieldName(),item);
}
FileItem uplFile=(FileItem)fields.get("NewFile");
String fileNameLong=uplFile.getName();
fileNameLong=fileNameLong.replace('\\','/');
String[] pathParts=fileNameLong.split("/");
String fileName=pathParts[pathParts.length-1];
long uploadFileSize = uplFile.getSize();
log.info("上传的文件大小为: ["+uploadFileSize+"]");
log.info("上传的文件名称为:["+fileName+"]");
String nameWithoutExt=getNameWithoutExtension(fileName);
String ext=getExtension(fileName);
File pathToSave=new File(currentDirPath,fileName);
//fileUrl=currentPath+"/"+fileName;
fileUrl=currentPath;
if(extIsAllowed(typeStr,ext,uploadFileSize)) {
//确保文件目录存在
if(!addUserNameFile.exists()){
addUserNameFile.mkdirs();
}
int counter=1;
newName = fileName;
while(pathToSave.exists()){
newName=nameWithoutExt+"("+counter+")"+"."+ext;
//fileUrl=currentPath+"/"+newName;
fileUrl=currentPath;
retVal="201";
pathToSave=new File(currentDirPath,newName);
counter++;
}
uplFile.write(pathToSave);
}
else {
//执行size过大提示信息
if(!retVal.equals("88")){
retVal="202";
errorMessage="";
if (debug) System.out.println("无效的文件类型: " + ext);
}else{
errorMessage="上传文件过大,该文件类型上传的大小允许在 "+typeAllowedSize+" 字节范围";
log.info("上传文件名称为:["+fileName+"]的文件大小为: ["+uploadFileSize+"] 超过 {"+typeAllowedSize+"}的允许范围!");
if (debug) System.out.println("上传文件过大: " + ext);
}
}
}catch (Exception ex) {
if (debug) ex.printStackTrace();
retVal="203";
}
}
else {
retVal="1";
errorMessage="无法上传文件. 请检查 WEB-INF/web.xml 文件!";
}
out.println("<script type=\"text/javascript\">");
out.println("window.parent.OnUploadCompleted("+retVal+",'"+fileUrl+"','"+newName+"','"+errorMessage+"');");
out.println("</script>");
out.flush();
out.close();
if (debug) System.out.println("--- END DOPOST ---");
}
/*
* This method was fixed after Kris Barnhoorn (kurioskronic) submitted SF bug #991489
*/
private static String getNameWithoutExtension(String fileName) {
return fileName.substring(0, fileName.lastIndexOf("."));
}
/*
* This method was fixed after Kris Barnhoorn (kurioskronic) submitted SF bug #991489
*/
private String getExtension(String fileName) {
return fileName.substring(fileName.lastIndexOf(".")+1);
}
/**
* Helper function to convert the configuration string to an ArrayList.
*/
private ArrayList stringToArrayList(String str) {
if(debug) System.out.println(str);
String[] strArr=str.split("\\|");
ArrayList tmp=new ArrayList();
if(str.length()>0) {
for(int i=0;i<strArr.length;++i) {
if(debug) System.out.println(i +" - "+strArr[i]);
tmp.add(strArr[i].toLowerCase());
}
}
return tmp;
}
/**
* Helper function to verify if a file extension is allowed or not allowed.
*/
private boolean extIsAllowed(String fileType, String ext,long size) {
ext=ext.toLowerCase();
ArrayList allowList=(ArrayList)allowedExtensions.get(fileType);
ArrayList denyList=(ArrayList)deniedExtensions.get(fileType);
long allowSize = ((Long)allowedSize.get(fileType)).longValue();
typeAllowedSize = allowSize;
if(allowList.size()==0){
if(denyList.contains(ext)){
return false;
}else{
if(size <= allowSize){
return true;
}
else{
retVal = "88"; //提示文件过大特殊符号
return false;
}
}
}
if(denyList.size()==0){
if(allowList.contains(ext)){
if(size <= allowSize){
return true;
}
else{
retVal = "88";
return false;
}
}
else{
return false;
}
}
return false;
}
}
支持文件大小控制
/*
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: SimpleUploaderServlet.java
* Java File Uploader class.
*
* Version: 2.3
* Modified: 2005-08-11 16:29:00
*
* File Authors:
* Simone Chiaretta (simo@users.sourceforge.net)
*/
package com.fredck.FCKeditor.uploader;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import org.apache.commons.fileupload.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
/**
* Servlet to upload files.<br>
*
* This servlet accepts just file uploads, eventually with a parameter specifying file type
*
* @author Simone Chiaretta (simo@users.sourceforge.net)
*/
public class SimpleUploaderServlet extends HttpServlet {
private static String baseDir;
private static boolean debug=false;
private static boolean enabled=false;
private static Hashtable allowedExtensions;
private static Hashtable deniedExtensions;
private static Hashtable allowedSize;//限制文件大小
private static String retVal="0";
private static long typeAllowedSize;
private static Logger log = Logger.getLogger(SimpleUploaderServlet.class);
/**
* Initialize the servlet.<br>
* Retrieve from the servlet configuration the "baseDir" which is the root of the file repository:<br>
* If not specified the value of "/UserFiles/" will be used.<br>
* Also it retrieve all allowed and denied extensions to be handled.
*
*/
public void init() throws ServletException {
debug=(new Boolean(getInitParameter("debug"))).booleanValue();
if(debug) System.out.println("\r\n---- SimpleUploaderServlet initialization started ----");
baseDir=getInitParameter("baseDir");
enabled=(new Boolean(getInitParameter("enabled"))).booleanValue();
if(baseDir==null)
baseDir="/EpUserFiles/";
String realBaseDir=getServletContext().getRealPath(baseDir);
File baseFile=new File(realBaseDir);
if(!baseFile.exists()){
baseFile.mkdir();
}
allowedExtensions = new Hashtable(3);
deniedExtensions = new Hashtable(3);
allowedSize = new Hashtable(3);
allowedExtensions.put("File",stringToArrayList(getInitParameter("AllowedExtensionsFile")));
deniedExtensions.put("File",stringToArrayList(getInitParameter("DeniedExtensionsFile")));
allowedSize.put("File", new Long(getInitParameter("AllowedFileSize")).longValue());
allowedExtensions.put("Image",stringToArrayList(getInitParameter("AllowedExtensionsImage")));
deniedExtensions.put("Image",stringToArrayList(getInitParameter("DeniedExtensionsImage")));
allowedSize.put("Image", new Long(getInitParameter("AllowedImageSize")).longValue());
allowedExtensions.put("Flash",stringToArrayList(getInitParameter("AllowedExtensionsFlash")));
deniedExtensions.put("Flash",stringToArrayList(getInitParameter("DeniedExtensionsFlash")));
allowedSize.put("Flash", new Long(getInitParameter("AllowedFlashSize")).longValue());
if(debug) System.out.println("---- SimpleUploaderServlet initialization completed ----\r\n");
}
/**
* Manage the Upload requests.<br>
*
* The servlet accepts commands sent in the following format:<br>
* simpleUploader?Type=ResourceType<br><br>
* It store the file (renaming it in case a file with the same name exists) and then return an HTML file
* with a javascript command in it.
*
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (debug) System.out.println("--- BEGIN DOPOST ---");
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Cache-Control","no-cache");
PrintWriter out = response.getWriter();
String typeStr=request.getParameter("Type");
String currentPath=baseDir+typeStr;
//在此为每个能上传图片的用片增加一个user目录,利用session来做
currentPath = currentPath+"/userName/";
String currentDirPath=getServletContext().getRealPath(currentPath);
currentPath=request.getContextPath()+currentPath;
File addUserNameFile=new File(currentDirPath);
if(!addUserNameFile.exists()){
addUserNameFile.mkdirs();
}
if (debug) System.out.println(currentDirPath);
String newName="";
String fileUrl="";
String errorMessage="";
if(enabled) {
DiskFileUpload upload = new DiskFileUpload();
upload.setHeaderEncoding("utf-8");
try {
List items = upload.parseRequest(request);
Map fields=new HashMap();
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField())
fields.put(item.getFieldName(),item.getString());
else
fields.put(item.getFieldName(),item);
}
FileItem uplFile=(FileItem)fields.get("NewFile");
String fileNameLong=uplFile.getName();
fileNameLong=fileNameLong.replace('\\','/');
String[] pathParts=fileNameLong.split("/");
String fileName=pathParts[pathParts.length-1];
long uploadFileSize = uplFile.getSize();
log.info("上传的文件大小为: ["+uploadFileSize+"]");
log.info("上传的文件名称为:["+fileName+"]");
String nameWithoutExt=getNameWithoutExtension(fileName);
String ext=getExtension(fileName);
File pathToSave=new File(currentDirPath,fileName);
//fileUrl=currentPath+"/"+fileName;
fileUrl=currentPath;
if(extIsAllowed(typeStr,ext,uploadFileSize)) {
//确保文件目录存在
if(!addUserNameFile.exists()){
addUserNameFile.mkdirs();
}
int counter=1;
newName = fileName;
while(pathToSave.exists()){
newName=nameWithoutExt+"("+counter+")"+"."+ext;
//fileUrl=currentPath+"/"+newName;
fileUrl=currentPath;
retVal="201";
pathToSave=new File(currentDirPath,newName);
counter++;
}
uplFile.write(pathToSave);
}
else {
//执行size过大提示信息
if(!retVal.equals("88")){
retVal="202";
errorMessage="";
if (debug) System.out.println("无效的文件类型: " + ext);
}else{
errorMessage="上传文件过大,该文件类型上传的大小允许在 "+typeAllowedSize+" 字节范围";
log.info("上传文件名称为:["+fileName+"]的文件大小为: ["+uploadFileSize+"] 超过 {"+typeAllowedSize+"}的允许范围!");
if (debug) System.out.println("上传文件过大: " + ext);
}
}
}catch (Exception ex) {
if (debug) ex.printStackTrace();
retVal="203";
}
}
else {
retVal="1";
errorMessage="无法上传文件. 请检查 WEB-INF/web.xml 文件!";
}
out.println("<script type=\"text/javascript\">");
out.println("window.parent.OnUploadCompleted("+retVal+",'"+fileUrl+"','"+newName+"','"+errorMessage+"');");
out.println("</script>");
out.flush();
out.close();
if (debug) System.out.println("--- END DOPOST ---");
}
/*
* This method was fixed after Kris Barnhoorn (kurioskronic) submitted SF bug #991489
*/
private static String getNameWithoutExtension(String fileName) {
return fileName.substring(0, fileName.lastIndexOf("."));
}
/*
* This method was fixed after Kris Barnhoorn (kurioskronic) submitted SF bug #991489
*/
private String getExtension(String fileName) {
return fileName.substring(fileName.lastIndexOf(".")+1);
}
/**
* Helper function to convert the configuration string to an ArrayList.
*/
private ArrayList stringToArrayList(String str) {
if(debug) System.out.println(str);
String[] strArr=str.split("\\|");
ArrayList tmp=new ArrayList();
if(str.length()>0) {
for(int i=0;i<strArr.length;++i) {
if(debug) System.out.println(i +" - "+strArr[i]);
tmp.add(strArr[i].toLowerCase());
}
}
return tmp;
}
/**
* Helper function to verify if a file extension is allowed or not allowed.
*/
private boolean extIsAllowed(String fileType, String ext,long size) {
ext=ext.toLowerCase();
ArrayList allowList=(ArrayList)allowedExtensions.get(fileType);
ArrayList denyList=(ArrayList)deniedExtensions.get(fileType);
long allowSize = ((Long)allowedSize.get(fileType)).longValue();
typeAllowedSize = allowSize;
if(allowList.size()==0){
if(denyList.contains(ext)){
return false;
}else{
if(size <= allowSize){
return true;
}
else{
retVal = "88"; //提示文件过大特殊符号
return false;
}
}
}
if(denyList.size()==0){
if(allowList.contains(ext)){
if(size <= allowSize){
return true;
}
else{
retVal = "88";
return false;
}
}
else{
return false;
}
}
return false;
}
}
相关推荐
- **文件上传安全**:确保对上传文件进行类型检查和大小限制,防止恶意文件上传。 - **XSS防护**:由于编辑的内容会被插入到网页中,所以需要防范跨站脚本攻击(XSS)。 - **权限控制**:根据用户角色设置编辑器...
2. 在JSF页面中引入FCKeditor:在需要使用编辑器的JSF页面中,添加FCKeditor的JavaScript和CSS引用,如: ```html <h:outputScript library="fckeditor" name="fckeditor.js" target="head" /> ...
3. **配置Servlet**:FCKeditor通常通过一个Servlet来处理上传文件和图片。在web.xml文件中,需要配置FCKeditor的Servlet映射,指定URL路径和Servlet类。 4. **编辑JSP页面**:在需要使用富文本编辑功能的JSP页面中...
第15章 在线文件上传和下载(struts 2.x+fileupload) 15.1 在线文件上传和下载模块原理 15.2 文件上传组件fileupload 15.3 初步使用文件上传组件(components-fileupload) 15.4 单文件的上传 15.5 多...
凯撒加密解密程序 1个目标文件 1、程序结构化,用函数分别实现 2、对文件的加密,解密输出到文件 利用随机函数抽取幸运数字 简单 EJB的真实世界模型(源代码) 15个目标文件 摘要:Java源码,初学实例,基于EJB的真实...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...
Java文件上传组件 COS FAT文件系统读写类库 fat32-lib fat32-lib 是一个用来读写 FAT 16/32 格式文件系统的纯 Java 类库(纯的)。 Eclipse的HTML格式化插件 Eclipse Tidy Eclipse HTML Tidy 是一款 Eclipse 的...