求教,再用commons-fileupload上传组件的Servlet中调用Js的问题
各位高手们,小弟最近在做Video网站,优酷这种功能的小网站,现在遇到的问题是:在Servlet中调用HTML代码,触发JS函数,可是报错是:
Stack overflowline at line 3行,
求教各位高手们,能否帮帮小弟,小弟一看大功告成,必将感激涕零,犹如枯木逢春!
JSP页面代码
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*" errorPage=""%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>钟毅播客----后台上传视频</title>
<style>
.prog-border {
height: 15px;
width: 205px;
background: #fff;
border: 1px solid #000;
margin: 0;
padding: 0;
}
.prog-bar {
height: 11px;
margin: 2px;
padding: 0px;
background: #178399;
font-size: 10pt;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
</style>
<script src="js/prototype.js" language="JavaScript"
type="text/javascript"></script>
<script type="text/javascript" language="JavaScript">
var updater = null;
function startStatusCheck() {
var fileValue=document.getElementById("fileId").value;
if(fileValue==null || fileValue==""){
alert("请添加上传文件");
return false;
}else{ //否则
$('submitButton').disabled = true;
updater = new Ajax.PeriodicalUpdater(
'status',
'fileupload',
{asynchronous:true, frequency:1, method: 'get', parameters: 'c=status&t='+new Date(), onFailure: reportError});
return true;
}
}
function reportError(request){
alert("aaaa");
$('submitButton').disabled = false;
$('status').innerHTML = '<div class="error"><b>Error communicating with server. Please try again.</b></div>';
}
//杀死更新
function killUpdate(message){
alert("aaaa");
$('submitButton').disabled = false;
if(null!=updater){
updater.stop();
}
if(message != ''){
$('status').innerHTML = '<div class="error"><b>Error processing results: ' + message + '</b></div>';
}else{
new Ajax.Updater('status',
'fileupload',
{asynchronous:true, method: 'get', parameters: 'c=status', onFailure: reportError});
}
}
</script>
</head>
</html>
Servlet代码
package upload;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.script.ScriptEngineManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.mr.dbo.MediaDao;
import com.mr.model.MediaInfo;
import com.mr.servlet.OperatingVideoOneThread;
import com.mr.servlet.OperatingVideoTwoThread;
/*******************************************************************************
*
* 上传的Servlet类
*
* @author Owner
*
*/
public class UploadServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
request.setCharacterEncoding("GBK"); // 设置request的编码格式 为 GBK
response.setCharacterEncoding("GBK"); // 设置response的编码格式为 GBK
response.setContentType("text/html; charset=GBK"); // 设置文本类型为 纯文本类型
HttpSession session = request.getSession(); // 创建HttpSession对象
if ("status".equals(request.getParameter("c"))) { // 如果请求中c的值为status
doStatus(session, response); // 调用doStatus方法(刚开始调用)
} else { // 否则
doFileUpload(session, request, response); // 调用doFileUpload方法
}
}
//......................................我省略了一些代码,这是哪个出问题的方法,有心人解决一下
/***************************************************************************
* 发送完成响应的方法(处理出错信息的方法)
*
* @param response
* 响应对象
* @param message
* 提示信息字符串
* @throws IOException
* 抛出系统的异常
*
*
* Error(stack overflow at line 3(发生了一种错误: 栈溢出在第三行 ))
* @throws ServletException
*
*/
private void sendCompleteResponse(HttpServletRequest request,HttpServletResponse response,
String message) throws IOException, ServletException {
if (message == null) { // 如果提示信息的字符串为空,输出客户端的HTML如下
//注意:经过我调试,错误发生在这里,有经验的高人们一看便知 Error(stack overflow at line 3(发生了一种错误: 栈溢出在第三行 ))
// response.setContentType("text/html");
// PrintWriter out = response.getWriter();
// out.println("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01
// Transitional//EN'>");
// out.println("<html>");
// out.println("<head><script type='text/javascript'>function
// killUpdate() { window.parent.killUpdate(''); }</script></head>");
// out.println("<body onload='killUpdate()'>");
// out.println("</body>");
// out.println("</html>");
// out.flush();
// out.close();
} else { // 否则,输出客户端的HTML如下
//注意:经过我调试,错误发生在这里,有经验的高人们一看便知 Error(stack overflow at line 3(发生了一种错误: 栈溢出在第三行 ))
// response.setContentType("text/html");
// PrintWriter out = response.getWriter();
// out.println("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01
// Transitional//EN'>");
// out.println("<html>");
// out.println("<head><script type='text/javascript'>function
// killUpdate() { window.parent.killUpdate('" + message + "');
// }</script></head>");
// out.println("<body onload='killUpdate()'>");
// out.println("</body>");
// out.println("</html>");
// out.flush();
// out.close();
}
}
这段代码的格式转换如果各位有心的话可以用用,就当我开源奉送了,经过测试很不错!
还有调用flv的进度条修复工具修复,注意不是完整代码!
希望这里有罕见的牛人们帮小弟一把,小弟已经使出全力,快要 空手劈石头的心 都有!
--------------------编程问答-------------------- http://d7.qjwm.com/download.aspx?down=ok&filepath=leoadmin2134%2fuploadDemo.zip
写好的commons-fileupload上传Demo,可以直接中,代码简洁易懂,内含jar包
补充:Java , Java EE