本人的开发平台是tomcat+mysql, 在开发的过程中, 采用了ewebeditor控件进行文本的编辑;具体说明如下:bgrj_insert.jsp页面包含ewebeditor控件, 该控件主要负责content表单域,由于该页面的表单还提供文件上传的功能, 采用了fileupload组件, 对于表单域的提取比较特殊(见bgrjsoftservlet.java), 页面提交到bgrjsoftservlet进行处理入库,主要代码如下:bgrjsoftservlet.java是处理bgrj_insert.jsp的servletfunction.java负责gb2312-->iso8859_1, 和iso8859_1-->gb2312, 但对于ewebeditor似乎不奏效,
望高手指点, 急!急急!!急急急!!!
望高手指点, 急!急急!!急急急!!!
解决方案 »
- Unable to locate configuration files of the name struts-plugin.xml, skipping
- Jquery ui tabs 加载XXX.action的页面
- maven新手提问
- 定位 //TODO的快捷键是什么?
- 为什么jsp提交的数据要做iso-8859-1转码?
- 请教,TOMCAT配连接池的出现问题
- JSF的初级问题,就是调不通,不知道什么原因。
- 页面出现乱码
- 求助:jsp连接mysql问题报错
- portlet之间的通信问题?
- 这个代码书上抄的,与光盘里的比较过,看不出差别,但是我的不能用,光盘里的可以。烦请各位大哥大姐看看。
- Java操作ORACLE数据库Clob字段,我插入一个34k的文本的时候报错 java.sql.SQLException ora-21560:argument is null,invalid,or ou
<%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*" errorPage="" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>办公软件</title>
<link href="../inc/admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
margin-top: 50px;
}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="post" enctype="multipart/form-data" action="bgrjsoftservlet">
<table width="97%" height="306" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#D4D0C8" bgcolor="#000000" class="table">
<tr>
<th height="20" colspan="2" bgcolor="#FF9999" class="border3D" scope="col">添加办公软件</th>
</tr>
<tr>
<th width="14%" height="32" bgcolor="#FF9999" class="detail" scope="col"><div align="right"><strong>标题</strong></div></th>
<th width="86%" height="32" bordercolor="#FF0000" bgcolor="#FFFFFF" class="bgbody" scope="col"><div align="left">
<input name="title" type="text" id="title" size="50" />
(<span class="STYLE3">*</span>)</div></th>
</tr>
<tr>
<td height="15" bgcolor="#FF9999" class="detail"><div align="right"><strong>日期</strong></div></td>
<td height="15" bordercolor="#666666" bgcolor="#FFFFFF" class="bgbody"><label></label>
<input name="date" type="text" id="date" size="50" />
(<span class="STYLE3">*</span>)(2005-11-25)
<div align="center"></div></td>
</tr>
<tr>
<td height="112" bgcolor="#FF9999" class="detail"><div align="right"><strong>说明</strong></div></td>
<td height="112" bordercolor="#666666" bgcolor="#FFFFFF" class="bgbody"><label>
<input type="hidden" name="content" value="请在此添加内容">
<iframe id="eWebEditor1" src="../ewebeditor/eWebEditor.jsp?id=content&style=standard" frameborder="0" scrolling="no" width="640" height="350"></iframe>
(<span class="STYLE3">*</span>)</label>
<div align="center"></div></td>
</tr>
<tr>
<td height="15" bgcolor="#FF9999" class="detail"><div align="right"><strong>文件</strong></div></td>
<td height="15" bordercolor="#666666" bgcolor="#FFFFFF" class="bgbody"><input name="picture" type="file" id="picture" size="50" /></td>
</tr>
<tr>
<td height="15" bgcolor="#FF9999" class="detail"><div align="right"><strong>作者</strong></div></td>
<td height="15" bordercolor="#666666" bgcolor="#FFFFFF" class="bgbody"><input name="author" type="text" id="author" size="50" /></td>
</tr>
<tr>
<td height="15" bgcolor="#FF9999" class="detail"><div align="right"><strong>关键字</strong></div></td>
<td height="15" bordercolor="#666666" bgcolor="#FFFFFF" class="bgbody"><input name="key" type="text" id="key" size="50" /></td>
</tr>
<tr>
<td height="15" bgcolor="#FF9999" class="detail"><div align="right"><strong>备注</strong></div></td>
<td height="15" bordercolor="#666666" bgcolor="#FFFFFF" class="bgbody"><textarea name="re" cols="50" rows="2" id="re">备注</textarea>
<div align="center"></div></td>
</tr>
</table>
<label>
<div align="center">
<div align="center">
<input type="submit" name="Submit" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</div>
</div>
</label>
<label></label>
<label></label>
<label></label>
<input type="hidden" name="action" value="insert" />
</form>
<table>
</table>
</body>
</html>
/**********************bgrjsoftservlet .java******************/
package software;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import hxbank.DB.DBconn;
import org.apache.commons.fileupload.*;
import news.newItem;
import common.function;public class bgrjsoftservlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=8859_1";
private String tempPath = "c:\\hxbank\\upload\\tmp\\"; // 临时文件目录 newItem ni = new newItem();//新闻条目
List fileItems;
DBconn dbconn = new DBconn();
RequestDispatcher dispatch = null;
String action; //操作类型:添加,删除,修改
String sql=null;
String id;
Iterator i; //Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uploadPath=request.getSession().getServletContext().getRealPath("/upload/bgrj/file");
response.setContentType(CONTENT_TYPE);
//request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter(); action = request.getParameter("action");
//System.out.println(request.getParameter("id"));
String type = (String)request.getSession().getAttribute("type");//判断用户权限
System.out.println("type=" + type);
System.out.println("action=" + action); //如果用户权限满足条件
if (type!=null && type.equals("15"))
{
//multitype form data
if (action==null)
{
//获取表单中的文本域
try
{
getFormContent(request);
i = fileItems.iterator();
while(i.hasNext())
{
FileItem fi = (FileItem)i.next();
if(fi.isFormField())
{
String fn = fi.getFieldName();
String fv = function.ChineseToUnicode(fi.getString());
String fv = new String(fi.getString().getBytes("GBk"),"ISO8859_1");
if (fn.equals("action")) action = fv;
else if(fn.equals("id")) id = fv ;
else if(fn.equals("title")) ni.setTitle(fv) ;
else if(fn.equals("date")) ni.setDate(fv);
else if(fn.equals("picture")) ni.setPicture(new String(fi.getString().getBytes("GBK"),"ISO8859_1"));
else if(fn.equals("content")) ni.setContent((fv));
else if(fn.equals("author")) ni.setAuthor(fv);
else if(fn.equals("key")) ni.setKey(fv);
else if(fn.equals("re")) ni.setRe(fv);
System.out.println("id"+id);
}
}
}catch(Exception fue)
{
fue.printStackTrace();
}
if (action.equals("insert"))
{
//完成文件的上传
try {
// 依次处理每一个文件:
i = fileItems.iterator();
while (i.hasNext()) { FileItem fi = (FileItem) i.next();
if(!fi.isFormField())
{
// 获得文件名,这个文件名包括路径: String fileName = (fi.getName());
System.out.println(fileName);
fileName = fileName.replace(':','_');
fileName = fileName.replace(' ','_');
fileName = fileName.replace('\\','_');
System.out.println("filename="+fileName);
//mysql不接受'\\'字符
fi.write(new File(uploadPath + fileName));
ni.setPicture(fileName);
}
}
} catch(Exception e) {
// 可以跳转出错页面
System.out.print(" upload file error");
e.printStackTrace();
dispatch = this.getServletContext().getRequestDispatcher("/admin/software/error.jsp");
}
//文件上传成功后, 插入记录
sql = "insert into bgrjsoft values(null," +
"'" + ni.getTitle()+ "'," +
"'" + ni.getDate() + "'," +
"'" + ni.getContent() + "'," +
"'" + ni.getRe() + "',"+
"'" + function.ChineseToUnicode(ni.getPicture()) + "'," +
"'" + ni.getAuthor() + "'," +
"'" + ni.getKey() + "')"; System.out.println(sql);
dbconn.executeUpdate(sql);
//request.getSession().setAttribute("queryAnswer", dbconn.executeQuery(sql));//
dispatch= this.getServletContext().getRequestDispatcher("/admin/software/bgrj_view.jsp"); }
} } //用户类型检测不满足跳转到check_fail.jsp
else
{
dispatch = this.getServletContext().getRequestDispatcher("/admin/check_fail.jsp");
}
dispatch.forward(request, response);
dbconn.close();
} public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}//将request的内容写入到List中
private void getFormContent(HttpServletRequest request){
try {
//Ensuring that the request is actually a file upload request is straightforward, but FileUpload makes it simplicity itself, by providing a static method to do just that.
if( FileUpload.isMultipartContent(request))
{
DiskFileUpload fu = new DiskFileUpload();
// 设置最大文件尺寸,这里是4MB
fu.setSizeMax(4194304);
// 设置缓冲区大小,这里是4kb
fu.setSizeThreshold(4096);
// 设置临时目录:
fu.setRepositoryPath(tempPath);
// 得到所有的文件:
fileItems = fu.parseRequest(request); }
}catch(Exception e)
{
e.printStackTrace();
}}
//Clean up resources
public void destroy() {
dbconn.close();
}
}
package common;
import java.io.*;public class function {
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
} public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
}