Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Framework getOutputStream() has already been called for this response

Have Programming Question? Ask it here!
 
 
 


raghavendra
getOutputStream() has already been called for this response
0 Answer(s)      a year and 7 months ago
Posted in : Framework


hi to all,

i am trying to export some data from my project to excel file....while clicking on the icon i am getting the following error.....(i am using jboss6.1.0). help me how to solve this issue?

Servlet.service() for servlet action threw exception: java.lang.IllegalStateException: getOutputStream() has already been called for this response.

here is my jsp code:

<%@ page import="com.zyom.webclient.util.MozartCostUtils,java.util.*,com.zyom.struts.form.AtsRegionsForm,com.zyom.struts.form.MapCustomerForm,com.zyom.reuse.util.DateHandler,com.zyom.webclient.util.MozartConstants"%>
<%@ page language="java" pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
    prefix="bean"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
    prefix="html"%>

<title>JSP for UserLoginForm form</title>
<script type="text/javascript">
function filter_region(){
   var region_id=document.getElementById("regid").value;

   window.location="regionCustUserMap.do?method=Select&r="+region_id;

}
function popHelp(fname)
{

    window.open(fname,"TopAssblyFileformat","width=400,height=250,top=20,left=40,menubar=0,toolbar=0,status=0,location=0,scrollbars=1,resizable=1,dependent=1");
}

</script>
    </head>
    <body>

    <% if ((MozartCostUtils.isFirefox(request))) 
    {
    %>
        <br>
        <%} %>  
         <%
          String finditem="";

          if(request.getAttribute("finditem")!=null)
            finditem=request.getAttribute("finditem").toString();
         String finditem1="";

          if(request.getAttribute("finditem1")!=null)
            finditem1=request.getAttribute("finditem1").toString();
         %>
            <table>

                <tr>
                    <td    class="loggedinlabel"  >
                        Review Sales Regions, Roles Mapped to Regions (Exec, Cust User, ApAdm), Customer related data¬ ¬ ¬ ¬  <a       rel="nofollow">Help</a>  <br>
                    </td>
                    </tr>
                    <tr><td>¬ </td></tr>
            </table>
            <table>
            <tr>
            <td  class="loggedinlabel"   >                  
                    <form  method="post" action="regionCustUserMap.do">
                     <input type="text"  class="loggedin"  value="<%=finditem %>" name="search">  ¬ ¬ ¬ ¬ <input type="hidden" name="method"   value="FindCustomer"> <input type="submit"  class="loggedinlabel" title="Find By Customer" value="Find Customer">
                    </form>
                    </td>
            <td  class="loggedinlabel"   >                  
                    <form  method="post" action="regionCustUserMap.do">
                     ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ <input type="text"  class="loggedin"  value="<%=finditem1%>" name="search1">  ¬ ¬ ¬ ¬ <input type="hidden" name="method"   value="Find"> <input type="submit"  class="loggedinlabel" title="Find By SalesID" value="Find SalesID">
                    </form>
                    </td>
            </tr></table>
            <table>
            <html:form action="regionCustUserMap.do">
                <tr>
                <td  class="loggedinlabel" >
                    <bean:message key="gloabl.asof" />
                </td>
                <td    class="loggedin" >
                    <%=(DateHandler.getDateInSpecifiedFormat(
                            new java.util.Date(),
                            MozartConstants.MOZART_DATE_FORMAT))%>
                </td>
                <td>¬ </td><td>¬ </td><td>¬ </td>
                <td  class="loggedinlabel" >Select SalesRegion:</td>
                <td  class="loggedinlabel" >
                     <html:select  styleClass="loggedin"  onchange="filter_region()" styleId="regid" property="regid">
                     <html:option value="0">ALL</html:option>
                      <html:options collection="regions_list"  property="id"  labelProperty="name"  ></html:options>     
                      </html:select>
                    ¬ ¬ ¬   
                </td>
                </tr>
        </html:form>
                </table>
                <%
            String divStyle = "style=\"overflow:auto;height:550;width:1030;\"";
                String tBodyStyle = "style=\"overflow:auto;overflow-x:hidden;\"";
                if ((MozartCostUtils.isFirefox(request))) {

                    divStyle = "style=\"overflow:auto;height:550;width:1030;\"";
                    tBodyStyle = "style=\"overflow:auto;overflow-x:hidden;height:200;\"";
                }
            %>
<hr size="1"  noshade>
<table    >
            <tr>
             <html:form   action="regionCustUserMapXl.do">
             <td>
                                <input alt="Press GO, Then click Export to Excel" name="CVS" class="loggedinlabel"
                                    type="image" value="Export Excel" src="images/xls.gif"
                                    onmouseover="Tip('Press Click Export to Excel')" />     
        </td>       
        <td      class="loggedinlabel"   >

        </td>
        </html:form>             
            </tr>
        </table> 
<html:form action="regionCustUserMap.do">
<div class="autoHeight" style="width:900px;height:1515px;margin-top:10px; margin-bottom:10px;">
<table   class="tablesorter" border="0"  > <%-- class="tablesorter" --%>
<thead class="ls">

        <th >Sales Region</th>
        <th >ROLES MAPPED AT REGION LEVEL (ALL EXCEPT SALES ID)</th>
        <th  >Customer</th>
        <th  >Country</th>
        <th  >Sales ID</th>

    </thead>

    <tbody class="ls1">
    <%ArrayList cust_list=(ArrayList)request.getAttribute("cust_list"); 
    for (int i = 0; i < cust_list.size(); i++) {
    MapCustomerForm mcf=(MapCustomerForm)cust_list.get(i);%>
    <TR class="<% if(i%2==0){%><%=""%><%}else{%><%="odd"%><%}%>">
                                <td width="148" nowrap="nowrap">
                                <%=mcf.getRegion()%>
                            </td>



                                <td width="408"  width="40">

                            <%=mcf.getUser_names() %>                   
                            </td>
                            <td width="188" nowrap="nowrap">
                                <%=mcf.getCustomer()%>
                            </td>
                            <td width="148" nowrap="nowrap">
                                <%=mcf.getLocation()%>
                            </td>
                            <td width="98" nowrap="nowrap">
                                <%=mcf.getSalesid()%>
                            </td>
    </tr>
    <%} %>
    </tbody>
</table></div>

        </html:form>
    </body>
</html>
 my action class code:
public class RegionCustUserMapXlAction extends DownloadAction {  

    protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form,  
        HttpServletRequest request, HttpServletResponse response)  
    throws Exception {  
    Date currentDatetime = new Date(System.currentTimeMillis());  
    SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy-HH-mm");  

    String myDate = formatter.format(currentDatetime);  

    String myDate1 = formatter.format(currentDatetime);  
    String fileName = "RegCustUsrMap_"+myDate+".xls";  
    String contentType = "application/vnd.ms-excel";  
    ServletContext servletCtx = this.servlet.getServletContext();  

    try{  

        String path = servletCtx.getRealPath(fileName);  
        WritableWorkbook workbook = Workbook.createWorkbook(new File(path));          
        HttpSession session = request.getSession(true);  
        List cust_list=new ArrayList();  
        cust_list=(ArrayList)session.getAttribute("cust_list");  

        jxl.write.Number num;  

        Calendar stDate = Calendar.getInstance();  
        Calendar endDate = Calendar.getInstance();  

        String temp = "";  

        SimpleDateFormat formatter1 = new SimpleDateFormat("MMM-dd,yyyy");     

        WritableSheet sheet = workbook.createSheet("RegCustUsrMap_"+myDate1, 1);   
        WritableFont arial10font = new WritableFont(WritableFont.ARIAL, 10);  
        WritableCellFormat arial10format = new WritableCellFormat (arial10font);  
        // sheet.mergeCells(0,0,2,0);  
        WritableFont times16font = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, true);  
        WritableCellFormat times16format = new WritableCellFormat (times16font);  
        times16format.setAlignment(jxl.format.Alignment.CENTRE);  
        // times16format.setBackground(Colour.BLUE);  
        times16format.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.MEDIUM,Colour.BLACK);  



        WritableFont datafont = new WritableFont(WritableFont.ARIAL , 10);  
        WritableFont datafont1 = new WritableFont(WritableFont.ARIAL , 10);  
        WritableFont datafont2 = new WritableFont(WritableFont.ARIAL , 10);  

        datafont1.setColour(Colour.BLUE);  
        datafont2.setColour(Colour.RED);  
        datafont.setColour(Colour.BLACK);  
        WritableCellFormat dataformat = new WritableCellFormat (datafont2);  
        WritableCellFormat dataformatApproved = new WritableCellFormat (datafont);  
        WritableCellFormat dataformatnotApproved = new WritableCellFormat (datafont1);  
        WritableCellFormat dataformatApproved1 = new WritableCellFormat (datafont);  
        dataformat.setAlignment(jxl.format.Alignment.LEFT);  
        dataformatApproved.setAlignment(jxl.format.Alignment.LEFT);  
        dataformatnotApproved.setAlignment(jxl.format.Alignment.LEFT);  
        dataformatApproved.setBackground(jxl.format.Colour.YELLOW);  
        dataformatApproved1.setAlignment(jxl.format.Alignment.LEFT);  
        dataformatApproved1.setBackground(jxl.format.Colour.BRIGHT_GREEN);  
        // times16format.setBackground(Colour.BLUE);  

        dataformatApproved.setBorder(jxl.format.Border.ALL , jxl.format.BorderLineStyle.MEDIUM_DASHED ,Colour.BLACK);  
        dataformatApproved1.setBorder(jxl.format.Border.ALL , jxl.format.BorderLineStyle.MEDIUM_DASHED ,Colour.BLACK);  

        Label label = new Label(0, 0, "Region Customer User Map",arial10format);  
        sheet.addCell(label);  
        label=new Label(0,2,"As of: ",arial10format);  
        sheet.addCell(label);  
        label=new Label(1,2,DateHandler.getTodaysDate(),arial10format);  
        sheet.addCell(label);  

        int i=0;  
        int j=3;  

        j++;  
        label = new Label(i, j, "Sales Region" ,times16format);  
        sheet.addCell(label);     
        i++;  
        label = new Label(i, j, "ROLES MAPPED AT REGION LEVEL (ALL EXCEPT SALES ID)" ,times16format);  
        sheet.addCell(label);     
        i++;  
        label = new Label(i, j, "Customer" ,times16format);  
        sheet.addCell(label);     
        i++;  
        label = new Label(i, j, "Country" ,times16format);  
        sheet.addCell(label);  
        i++;  
        label = new Label(i, j, "Sales Id" ,times16format);  
        sheet.addCell(label);     
        i++;  


        while(endDate.after(stDate)){  

        label = new Label(i, j, formatter1.format(new java.util.Date(stDate.getTimeInMillis())) ,times16format);  
        sheet.addCell(label);  
         i++;  
        stDate.add(Calendar.DATE, 7);  
         }      

    for (int count = 0; count < cust_list.size(); count++) {  
        MapCustomerForm mapCustomerForm=new MapCustomerForm();  
        mapCustomerForm = (MapCustomerForm) cust_list.get(count);  

          j++;  

            i=0;  
            label = new Label(i, j, mapCustomerForm.getRegion(),arial10format);  
            sheet.addCell(label);     
            i++;  
            label = new Label(i, j, mapCustomerForm.getUser_names(),arial10format);  
            sheet.addCell(label);     
            i++;  
            label = new Label(i, j,mapCustomerForm.getCustomer(),arial10format);  
            sheet.addCell(label);     
            i++;  
            label = new Label(i, j, mapCustomerForm.getLocation(),arial10format);  
            sheet.addCell(label);     
            i++;  
            label = new Label(i, j,mapCustomerForm.getSalesid(),arial10format);  
            sheet.addCell(label);  
            i++;  

        }  

    j=j+2;  

        workbook.write();  
        workbook.close();   

    }catch(Exception e){  

        System.out.print(e);  
    }     

    response.setHeader("Content-disposition", "attachment;filename="+ fileName );  

    return new ResourceStreamInfo(contentType, servletCtx, fileName);  
    }  
}  

Advertisement
View Answers

Related Tutorials/Questions & Answers:
 

 

 

DMCA.com