Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2012, 02:38 AM
bigjo bigjo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 bigjo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 32 sec
Reputation Power: 0
Servlets/JSP - GetOutputStream() has already been called for this response

Hi I have a program and wants to do an export to excell with a jsp file. I use for this the jxl-library.

But I got the following error:
Code:
org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  366)
	org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInt  erceptor.java:109)
	org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityI  nterceptor.java:83)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilt  er.java:97)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.ja  va:100)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuth  enticationFilter.java:78)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(Securit  yContextHolderAwareRequestFilter.java:54)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilt  er.java:35)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenti  cationFilter.java:177)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(Abst  ractAuthenticationProcessingFilter.java:187)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPe  rsistenceFilter.java:79)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:  378)
	org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:167)
	org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
	org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java  :88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:151)
	net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:129)
	org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManager  InViewFilter.java:113)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)


I don't find the problem. This is my code:
Code:
<%@ page import = "java.util.*, java.text.*, java.sql.*, java.net.*,java.io.*" %>  
<%@ page import = "jxl.*" %> 
<%@ page import = "java.sql.*" %>
<%@ include file="config.jsp" %>
<%@ include file="AdHocQueries_Pers_queryConstructor.jsp" %>
<%@ include file="AdHocQueries_OT_queryConstructor.jsp" %>
<%@ include file="getRole.jsp" %> 
<%@ include file="updateUserActivity.jsp" %>
<% 


	ArrayList<String> autorized_users = new ArrayList<String>();
	autorized_users.add("HRG Full Access");
    if(isAuthorized(autorized_users,db_ipp_addr,db_name,db_username, db_password, request.getUserPrincipal().getName()) == false){
		response.sendRedirect("notAuthorized.jsp"); 
	}

	boolean noLimit = false;
	String clause = "";
	String count = "";
	if (request.getParameter("clause") != null){
	clause = request.getParameter("clause");
	}else{
		clause = "";    
	} 
	
	String OT_filter = "";
	String Pers_filter = "";
	String OT_name = "";
	String Pers_name = "";
	String OT_nr  = request.getParameter("adhocMerge_OT"); 
	String Pers_nr = request.getParameter("adhocMerge_Pers"); 
	String initialPersSql = "";
	String postPersSql = "";
	String initialOTSql = "";
	String whereclauseOTSql = "";
	String MergeSelectedField = "";
	ArrayList<String> MergeSelectedFieldList = new ArrayList<String>();
	
	String count_row_pers = "0";
	
    Connection connection = null; 
    Statement statement = null; 
    ResultSet rs = null; 
    String connectionURL = "jdbc:mysql://" + db_ipp_addr + ":3306/" + db_name;
    Class.forName("com.mysql.jdbc.Driver").newInstance(); 
    connection = DriverManager.getConnection(connectionURL, db_username, db_password); 
    statement = connection.createStatement(); 
	
	String sql = "SELECT TheSQL,Filter FROM t_L1_HRB_global_adhoc_filters_updatable WHERE Nr = '"+OT_nr+"'";
	rs = statement.executeQuery(sql); 
	if (rs.next()) { OT_filter = rs.getString("TheSQL"); OT_name= rs.getString("Filter");}

	sql = "SELECT TheSQL,Filter FROM t_L1_HRB_global_adhoc_filters_updatable WHERE Nr = '"+Pers_nr+"'";
	rs = statement.executeQuery(sql); 
	if (rs.next()) { Pers_filter = rs.getString("TheSQL"); Pers_name= rs.getString("Filter");}
	
	

	initialPersSql = getSQL(Pers_filter.toLowerCase(), true) ;
	initialPersSql = initialPersSql.substring(0,initialPersSql.indexOf("ORDER BY"));
	initialOTSql = getOTSQL(OT_filter.toLowerCase()) ;
	postPersSql = initialPersSql.replace("ifnull(PD.Stamnummer,'') as STAMNUMMER,ifnull(PD.Graad_kort,'') as GRAAD_kort,ifnull(PD.Naam,'') as NAAM,ifnull(PD.Voornamen,'') as VOORNAMEN, ifnull(PD.Org,'') as ORG, ifnull(PD.orgnum,'') as ORGNUM ,","ifnull(PD.Stamnummer,'') as STAMNUMMER,");

	sql = "SELECT Table_Name_DB, FieldName_DB FROM t_L1_HRB_global_adhoc_selectfields WHERE AdHocType  = '1'";
			rs = statement.executeQuery(sql);
			String tempo = postPersSql.substring(postPersSql.indexOf("SELECT"), postPersSql.indexOf("FROM")).toLowerCase();
			while (rs.next()) { 
				if ((tempo.contains("pd."+rs.getString("FieldName_DB").toLowerCase()+",") ^ tempo.contains(rs.getString("Table_Name_DB")+"1"+rs.getString("FieldName_DB").toLowerCase()+",")) && !MergeSelectedField.toLowerCase().contains(rs.getString("FieldName_DB").toLowerCase())){
					MergeSelectedField+= ",T2."+rs.getString("FieldName_DB");
					if (!rs.getString("FieldName_DB").equals("Stamnummer")) MergeSelectedFieldList.add(rs.getString("FieldName_DB"));
				};
			}
			MergeSelectedField = MergeSelectedField.replace(",T2.Stamnummer","");		

	whereclauseOTSql = initialOTSql.substring(initialOTSql.indexOf("WHERE"));

	sql = "SELECT * "+MergeSelectedField+" FROM t_L1_HRB_global_org_ot AS OT LEFT JOIN ("+postPersSql+") AS T2 ON OT.Stamnummer = T2.Stamnummer " +whereclauseOTSql;



String sheetname = "Global "+version+" : Ad Hoc query OT"; 
OutputStream os = response.getOutputStream();// will write to the output stream WritableWorkbook 

	
 
   try{  
   response.reset ();  
   response.setContentType ( "application / vnd.ms-excel; charset = UTF-8");  
   response.setHeader ( "Content-Disposition", "attachment; filename =" + new String ( (sheetname+".xls").getBytes (), "iso-8859-1"));  

   int NrToAdd = MergeSelectedFieldList.size();
    
   jxl.write.WritableWorkbook wwb = jxl.Workbook.createWorkbook (os); 
   jxl.write.WritableSheet ws = wwb.createSheet ( sheetname, 0);  
   ws.getSettings().setOrientation(jxl.format.PageOrientation.LANDSCAPE);
   ws.getSettings().setScaleFactor(50);
   ws.getSettings().setFitWidth(1);
   ws.getSettings().setPaperSize(jxl.format.PaperSize.A3);
   HeaderFooter footer = new HeaderFooter();

...



Can someone help me?

Reply With Quote
  #2  
Old November 9th, 2012, 08:49 AM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,826 bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 9 h 9 m 26 sec
Reputation Power: 1248
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
I believe this may be the source of the problem

Code:
OutputStream os = response.getOutputStream();

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Servlets/JSP - GetOutputStream() has already been called for this response

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap