- - PR -
RequestDispatcherのエラーがおきまして。。。T.T
1
| 投稿者 | 投稿内容 | ||||||||
|---|---|---|---|---|---|---|---|---|---|
|
投稿日時: 2004-03-31 18:07
お世話になります。
org.apache.jasper.JasperException: getOutputStream()はこのレスポンスに対してすでに呼び出されています。というエラーが出ました。 何が悪いか全然分かりません。 ソースに何が変なのか教えてください。 よろしくお願いします。 import java.io.*; import java.text.*; import java.util.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import sun.net.smtp.SmtpClient; import org.apache.oro.text.perl.*; public class UrlRegistServlet extends HttpServlet { boolean login = false ; String jspPage = null; FileList_Bean fileBean = null; String LIST_BEAN = "FileList"; public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html; charset=Shift_JIS"); PrintWriter out = null; HttpSession session = req.getSession(); login = false ; out =new PrintWriter( res.getOutputStream(),true); String authType = req.getHeader( "Authorization" ); if( authType != null && authType.toUpperCase().startsWith( "BASIC" ) ) { String data[] = doDecode( authType ); res.setContentType( "text/html; charset=iso-2022-jp" ); if ( data[0].equals("userID") && data[1].equals("PW")) { login = true ; }else{ login = false ; } if ( !login) { res.setStatus(res.SC_UNAUTHORIZED); res.setHeader("WWW-Authenticate", "BASIC realm=\"check\"" ); }else { try{ fileBean = new FileList_Bean(); if( !fileBean.searchFile() ) { jspPage = "/jsp/japan/jpn/PRODUCTS/Intora/error.html" ; ServletContext context = getServletConfig().getServletContext(); RequestDispatcher rd = context.getRequestDispatcher(jspPage); rd.include(req, res); } req.setAttribute(LIST_BEAN, fileBean); jspPage = "/jsp/japan/jpn/PRODUCTS/Intora/indexall.jsp" ; ServletContext context = getServletConfig().getServletContext(); RequestDispatcher rd = context.getRequestDispatcher(jspPage); //ここでエラーがおきます。 rd.include(req, res);<==ここです。 }catch(Exception e){ RenesasDebug.write("nam", "e",e.toString()); //ここにきます。 jspPage = "/jsp/japan/jpn/PRODUCTS/Intora/error.html" ; ServletContext context = getServletConfig().getServletContext(); RequestDispatcher rd = context.getRequestDispatcher(jspPage); rd.include(req, res); } } }else { res.setStatus(res.SC_UNAUTHORIZED); res.setHeader("WWW-Authenticate", "BASIC realm=\"HITACHI\"" ); login = false ; } if ( !login) { //out =new PrintWriter( res.getOutputStream(),true); //out = res.getWriter(); String err_buf = "" ; err_buf += "<HTML><HEAD>" ; err_buf += "<TITLE>401 Authorization Required</TITLE>" ; err_buf += "</HEAD><BODY>" ; err_buf += "<H1>Authorization Required</H1>" ; err_buf += "This server could not verify that you " ; err_buf += "are authorized to access the document you " ; err_buf += "requested. Either you supplied the wrong " ; err_buf += "credentials (e.g., bad password), or your " ; err_buf += "browser doesn't understand how to supply " ; err_buf += "the credentials required.<P>" ; err_buf += "</BODY></HTML>" ; out.println(err_buf); } session.invalidate() ; if( out != null ) out.close(); } public String[] doDecode( String auth ) throws IOException { auth = auth.substring( 6 ); sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder(); auth = new String( dec.decodeBuffer( auth ) ); int i = auth.indexOf( ':' ); String ret[] = { auth.substring( 0, i ), auth.substring( i + 1 ) }; return ret; } public void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { doGet( req, res ); } } | ||||||||
|
投稿日時: 2004-03-31 18:21
すみません、発言の削除の仕方がわかりませんでした。
[ メッセージ編集済み 編集者: コガちゃん 編集日時 2004-03-31 19:27 ] | ||||||||
|
投稿日時: 2004-03-31 21:31
ServletResponse の getOutputStream() と getWriter() の両方を呼び出すことはできません。 ディスパッチ先の indexall.jsp で何らかの出力をしていると思うのですが、その出力先がjavax.servlet.jsp.JspWriter のサブクラス (のハズ) です。 この JspWriter が ServletResponse の PrintWriter オブジェクトに関係しているからなんじゃないかと思うのですが・・。 質問とは関係ありませんが、boolean login はインスタンス変数でいいんですか? すごく心配です。 | ||||||||
|
投稿日時: 2004-04-01 09:54
でゅうく様
ご丁寧な回答有難うございます。 はっきりはよくわかりませんが今のところ動いてます。 本当に有難うございました。 これからもよろしくお願いします。 ^^ | ||||||||
1
