标签:实现上传文件和图片
一、在web.xml中声明ConnectorServlet
打开fckeditor-java-2.4.1-bin/fckeditor-java-2.4.1/site/connector.html
复制以下代码
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>
net.fckeditor.connector.ConnectorServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>
/fckeditor/editor/filemanager/connectors/*
</url-pattern>
</servlet-mapping>
二、创建fckeditor.properties配置文件在classpath下
connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl
三、测试浏览图片
如果与struts整合仍需要做其它配置(修改web.xml文件中的过滤器/*改为*.action 或 *.jsp)
四、上传显示中可能出现乱码情况如何处理
创建包
cn.jbit.fckeditor
创建类
ConnectorServlet.java
复制java-core-2.4.1.jar/net.fckeditor.connector/ConnectorServlet中的内容
到我自定义的ConnectorServlet中
在doPost方法中添加如下代码
upload.setHeaderEncoding("UTF-8");
修改web.xml文件
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>
cn.jbit.fckeditor.ConnectorServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
五、创建中文目录出现乱码
修改ConnectorServlet文件中的代码
String newFolderStr = UtilsFile.sanitizeFolderName(
request
.getParameter("NewFolderName"));
修改为如下代码
String newFolderStr = UtilsFile.sanitizeFolderName(
new String(request
.getParameter("NewFolderName").getBytes("ISO8859-1"),"UTF-8"));
六、自定义用户目录
创建UserPathBuilder的实现类
public class MyUserPathBuild implements UserPathBuilder {
public String getUserFilesPath(HttpServletRequest request) {
String username = (String) request.getSession().getAttribute("username");
return "/userfiles/"+username;
}
}
在fckeditor.properties资源文件中配置
connector.userPathBuilderImpl=cn.jbit.fckeditor.MyUserPathBuild
在index.jsp页面添加登录代码,提交给doLogin.jsp处理
<form action="doLogin.jsp" method="post">
<label>用户名:</label>
<input type="text" name="username"/><br/>
<label>密码:</label>
<input type="password" name="password"/><br/>
<input type="submit" value="登录"/>
</form>
doLogin.jsp
<%
request.setCharacterEncoding("UTF-8");
String username = request.getParameter("username");
session.setAttribute("username",username);
response.sendRedirect("testfckeditor3.jsp");
%>
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1561333
标签:实现上传文件和图片
原文地址:http://suyanzhu.blog.51cto.com/8050189/1561333