在tomcat 7上找不到成功字符串jupload

时间:2016-08-08 02:05:23

标签: java jsp tomcat servlets jupload

我以前在tomcat 5.5中使用jupload,效果很好!现在我的任务是将tomcat升级到版本7(确切地说是7.0.70),并发现jupload不再有效。我没有改变代码一点。只是改变了tomcat发行版,(我甚至在服务器xml上使用了相同的连接器定义) 所以这是我的代码 jsp页面

<%@ page language="java" contentType="text/html; charset=cp1251"
    pageEncoding="cp1251"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page session="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=cp1251">
<title>Загрузка файлов</title>
<link rel=stylesheet type="text/css" href="/styles/style.css">
<style>
.td {
    valign: top
}
</style>
</head>
<body style="background-color: white;">
    <APPLET CODE="wjhk.jupload2.JUploadApplet" NAME="JUpload"
        ARCHIVE="${pageContext.request.contextPath}/applets/lib/jupload.jar"
        WIDTH="640" HEIGHT="300" MAYSCRIPT
        ALT="The java pugin must be installed.">
        -
        <c:choose>
            <c:when test="${param.par_type==1}">
                <param name="postURL"
                    value="${pageContext.request.contextPath}/protected/MultipleFileUpload?par_type=1" />
            </c:when>
            <c:when test="${param.par_type==2}">
                <param name="postURL"
                    value="${pageContext.request.contextPath}/protected/MultipleFileUpload?par_type=2" />
            </c:when>
            <c:when test="${param.par_type==3}">
                <param name="postURL"
                    value="${pageContext.request.contextPath}/protected/MultipleFileUpload?par_type=3" />
            </c:when>
            <c:otherwise>
                <param name="postURL"
                    value="${pageContext.request.contextPath}/protected/MultipleFileUpload" />
            </c:otherwise>
        </c:choose>
        <param name="afterUploadURL"
            value="${pageContext.request.contextPath}/protected/MultipleFileUpload" />
        <param name="allowedFileExtensions" value="xml/osf/zsf/plax" />
        <param name="afterUploadURL"
            value="javascript:alert('Загрузка файлов успешно завершена');window.opener.location.href = '../protected/sheet/plan/EducPlansStorage';window.close();" />
        <param name="showLogWindow" value="true" />
        <param name="debugLevel" value="0" />
        <param name="stringUploadSuccess" value="^SUCCESS" />
        <param name="lookAndFeel" value="system" />
    </APPLET>
</body>
</html>       

服务器端MultipleFileUpload Servlet

  package com.ieml.servlets.plan;

    import java.io.*;
    import java.sql.*;
    import java.util.*;

    import javax.servlet.*;
    import javax.servlet.http.*;

    import org.apache.commons.fileupload.*;

    import org.apache.commons.fileupload.disk.*;
    import org.apache.commons.fileupload.servlet.*;

    import com.ieml.Global;
    import com.ieml.util.*;

    /**
     * Servlet implementation class for Servlet: UploadInfoFileServlet
     *
     */
    public class MultipleFileUploadServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
        private static final long serialVersionUID = 1L;

        protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doPost(request, response);
        }   

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doPost(request, response);
        }   

        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
        {
            PrintWriter out = response.getWriter();
            String path = com.ieml.Global.getUploadDirectory();
            Integer type= ServletUtilities.getIntParameter(request, "par_type");
            if(path == null)
            {
                ServletUtilities.forwardErrorPage(request, response, "Не указано место хранения файлов");           
                return;         
            }
            if(type==null)
            {
                ServletUtilities.forwardErrorPage(request, response, "Не указан тип плана");            
                return;         
            }
            else
            {
                switch(type)
                {
                case 1:path+="/plans/incoming/"; break;
                case 2:path+="/plansMag/incoming/";break;
                case 3:path+="/plansSPO/incoming/";break;
                }
            }

            boolean isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(request));

            if (isMultipart) 
            {
                try
                {
                    FileItemFactory factory = new DiskFileItemFactory();
                    ServletFileUpload upload = new ServletFileUpload(factory);
                    upload.setHeaderEncoding("UTF-8");
                    List<?> items = upload.parseRequest(request);
                    Iterator<?> iter = items.iterator();
                    while(iter.hasNext())
                    {
                        FileItem item = (FileItem)iter.next();                
                        if (!item.isFormField()) 
                        {
                            String fileName = item.getName();
                            if(!fileName.endsWith(".xml") &&!fileName.endsWith(".XML") &&
                                    !fileName.endsWith(".osf") && !fileName.endsWith(".OSF") &&
                                    !fileName.endsWith(".zsf") && !fileName.endsWith(".ZSF")&&
                                    !fileName.endsWith(".plax") && !fileName.endsWith(".PLAX")
                                    )
                            {
                                ServletUtilities.forwardErrorPage(request, response, "Поддерживаемые формат файлов: .xml");
                                return;         
                            }
                            Connection conn = Global.getConnection();                   
                            try {

                                File f = new File(path,   fileName);
                                if(f.exists()) f.delete();                    

                                File uploadedFile = new File(path, fileName);
                                try
                                {
                                    item.write(uploadedFile);
                                }
                                catch(Exception e)
                                {
                                    e.printStackTrace();
                                    log(e.getMessage());
                                    ServletUtilities.forwardErrorPage(request, response, "Не могу записать файл.");
                                }
                            }                   
                            finally
                            {
                                conn.close();
                            }
                            break;
                        }
                    }
                    out.println("SUCCESS");
                }
                catch(SQLException e){
                    e.printStackTrace();
                }
                catch(FileUploadException fue){
                    fue.printStackTrace();
                    log(fue.getMessage());
                    ServletUtilities.forwardErrorPage(request, response, "Не могу принять файл.");              
                }
            }   
        }
    }  

这是我的errror的jupload日志 http://pastebin.com/xUaSjKdV

我认为,在jupload开始准备上传之后,由于某种原因,它会重定向到Web应用程序根目录(进而被重定向到需要登录的网站的受保护区域)。在这两种情况下,用户已经登录了转到jsp页面。因为某些奇怪的原因只是在登录页面内搜索成功字符串,当然不包含它,所以会弹出错误。我想知道为什么它首先重定向到Web应用程序根目录。我认为这可能与超时问题有关,将asyncTimeout的默认参数更改为&#34; 6000(此参数根据文档在5.5版本中不存在)但仍然没有运气。这是我在tomcat上localhost上的基本端口8080 Connecto

 <Connector  acceptCount="100"  protocol="org.apache.coyote.http11.Http11Protocol" connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192" maxSpareThreads="75" maxThreads="150" minSpareThreads="25" port="8080" redirectPort="8443"/>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我终于明白了,只有让它工作才能添加useHttpOnly =&#34; false&#34;到我的context.xml文件,所以它看起来像  &LT;上下文使用HttpOnly =&#34; false&#34; &GT;希望这也有助于其他人