Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法转发java.lang.illegalstateexception。响应已提交到jsp_Java_Jsp - Fatal编程技术网

无法转发java.lang.illegalstateexception。响应已提交到jsp

无法转发java.lang.illegalstateexception。响应已提交到jsp,java,jsp,Java,Jsp,我正在使用下面的jsp并获取java.lang.IllegalStateException无法转发。响应已提交到jsp。 我不明白发生了什么事?为什么会有这些例外 我试了很多。请帮我解决这个问题 String contentType = request.getContentType(); InputStream tmpInStream =null ; DataInputStream myInput = null; boolean isMultipartContent = Servl

我正在使用下面的jsp并获取
java.lang.IllegalStateException
无法转发。响应已提交到jsp。

我不明白发生了什么事?为什么会有这些例外

我试了很多。请帮我解决这个问题

   String contentType = request.getContentType();
    InputStream tmpInStream =null ;
DataInputStream myInput = null;
boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try 
{
    List  fields = upload.parseRequest(request);
    Iterator it = fields.iterator();
    while (it.hasNext()) 
    {
FileItem fileItem = (FileItem)it.next();
boolean isFormField = fileItem.isFormField();
if (isFormField==false) 
{
    fileName=fileItem.getName();
    log.printOut("[Upload] (When form field is false ) FileName: " + fileItem.getName() + " SIZE (BYTES): " + fileItem.getSize() );
    tmpInStream = fileItem.getInputStream();
    myInput =  new DataInputStream(tmpInStream);
    String tmpCSVData = fileItem.getString();
}
else 
{
    log.printOut("[Upload] (When form field is true ) FileName: " + fileItem.getName() + " SIZE (BYTES): " + fileItem.getSize() );
    csv = fileItem.getString();
}   
    }
}
catch (Exception e) 
{
    log.printErr("[Upload] Error while getting file :"+ e);
}


String thisLine; 
XMLParser xmlParser = new XMLParser();
String InputXml="";
String OutputXml="";
String csvType="";

try{

    Properties properties = new Properties();
    properties.load(new FileInputStream(System.getProperty("user.dir")+File.separator+"ips.properties"));
    String Ipsviewname=properties.getProperty("CsvIpsViewName");
    String Tranviewname=properties.getProperty("CsvTransViewName");
    log.printOut("[Upload] TableName (IPS)"+ Ipsviewname );
    log.printOut("[Upload] TableName (Transaction)"+ Tranviewname );
    while ((thisLine = myInput.readLine()) != null)
    {
String strar[] = thisLine.split(",");
log.printOut("[Upload] Line Split length "+ strar.length );
if(strar.length!=11 && strar.length!=5)
{
    RequestDispatcher rd = request.getRequestDispatcher("DownloadDocs.jsp?result=Invalid CSV");
    rd.forward(request, response);
}
if(strar.length==11)
{
    csvType="ips";
}
else
{

    csvType="Transaction";
}
log.writeXML("[Upload] INPUTXML "+ InputXml );
OutputXml = sessionBean.execute(InputXml);
log.writeXML("[Upload] OUTPUTXML "+ OutputXml );
xmlParser.setInputXML(OutputXml);
    }
   request.setAttribute ( "page","upload" );
   request.setAttribute ( "file", fileName );
   RequestDispatcher rd = request.getRequestDispatcher("csvtabl.jsp?csvType="+csvType+"");
   rd.forward(request, response);
}
catch (Exception e) 
{   
    RequestDispatcher rd =request.getRequestDispatcher("DownloadDocs.jsp?result=Invalid CSV");
    rd.forward(request, response);
    log.printErr("[Upload] Error while reading file :"+ e );}

您需要在第一次调用
RequestDispatcher.forward
方法后停止执行,否则代码将继续执行。在大多数情况下,您希望在每次转发后返回

在您的例子中,在while循环中进行转发,代码继续执行,并在方法末尾再次尝试转发

if(strar.length!=11 && strar.length!=5) {
    RequestDispatcher rd = request.getRequestDispatcher("DownloadDocs.jsp?result=Invalid CSV");
    rd.forward(request, response);
    return ;
}

(在其他地方也包括return)。

您需要在第一次调用
RequestDispatcher.forward
方法后停止执行,否则代码将继续执行。在大多数情况下,您希望在每次转发后返回

在您的例子中,在while循环中进行转发,代码继续执行,并在方法末尾再次尝试转发

if(strar.length!=11 && strar.length!=5) {
    RequestDispatcher rd = request.getRequestDispatcher("DownloadDocs.jsp?result=Invalid CSV");
    rd.forward(request, response);
    return ;
}
(也包括在其他地方返回)