alternative method to servletoutputstream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajos
    Contributor
    • Aug 2007
    • 283

    alternative method to servletoutputstream

    hi frnds,
    im seperating html views, which is inside my servlets into a seperate jsp.the servlet contains certain exception methods that shows certain exceptions(if present)..the servlet uses- out = httpservletresp onse.getOutputS tream();

    and
    method like--
    Code:
    static void printSQLException(SQLException sqlexception, ServletOutputStream servletoutputstream)
            throws IOException
        {
            servletoutputstream.print("<b>SQLException</b>\n<p>\n\n");
            for(; sqlexception != null; sqlexception = sqlexception.getNextException())
            {
                servletoutputstream.print("<b>SQLState:</b> " + sqlexception.getSQLState() + "<br>\n");
    inside the try..catch block of the service method..i have used RequestDispatch er.forward() method which forwards me to the jsp which i have seperated from the servlet...now i know that if i use RequestDispatch er.forward() i cannot use the servletoutputst ream property...can anybody suggest me an alternative for servletoutputst reams out.so that my servlet will forward the control to a jsp and also give me the exceptions when its needed....thann x in advance ....any help will be appreciated.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ajos
    hi frnds,
    im seperating html views, which is inside my servlets into a seperate jsp.the servlet contains certain exception methods that shows certain exceptions(if present)..the servlet uses- out = httpservletresp onse.getOutputS tream();

    and
    method like--
    Code:
    static void printSQLException(SQLException sqlexception, ServletOutputStream servletoutputstream)
            throws IOException
        {
            servletoutputstream.print("<b>SQLException</b>\n<p>\n\n");
            for(; sqlexception != null; sqlexception = sqlexception.getNextException())
            {
                servletoutputstream.print("<b>SQLState:</b> " + sqlexception.getSQLState() + "<br>\n");
    inside the try..catch block of the service method..i have used RequestDispatch er.forward() method which forwards me to the jsp which i have seperated from the servlet...now i know that if i use RequestDispatch er.forward() i cannot use the servletoutputst ream property...can anybody suggest me an alternative for servletoutputst reams out.so that my servlet will forward the control to a jsp and also give me the exceptions when its needed....thann x in advance ....any help will be appreciated.
    In the servlet
    [CODE=java]PrintWriter page = response.getWri ter();
    try {
    .....
    .....
    }
    catch(Exception e) {
    page.println(e. getStackTrace() );
    }
    ......
    request.getRequ estDispatcher(" JSPPathAndName. jsp").include(r equest, response);[/CODE]


    Then the exception trace will be output to the JSP as well.

    Comment

    • ajos
      Contributor
      • Aug 2007
      • 283

      #3
      hey,
      thanx for the prompt reply,i tried the printwriter page option also but its givin me http 500--
      type Exception report

      message

      description The server encountered an internal error () that prevented it from fulfilling this request.

      exception

      javax.servlet.S ervletException : Servlet execution threw an exception


      root cause

      java.lang.NoCla ssDefFoundError : publicity/PubMas
      publicity.PubMa ster.service(Pu bMaster.java:34 )
      javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)


      note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.


      --------------------------------------------------------------------------------

      Apache Tomcat/5.5.23


      the stack trace is---
      SEVERE: Servlet.service () for servlet PubMaster threw exception
      java.lang.NoCla ssDefFoundError : publicity/PubMas
      at publicity.PubMa ster.service(Pu bMaster.java:34 )
      at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
      at org.apache.cata lina.core.Appli cationFilterCha in.internalDoFi lter(Applicatio nFilterChain.ja va:269)
      at org.apache.cata lina.core.Appli cationFilterCha in.doFilter(App licationFilterC hain.java:188)
      at org.apache.cata lina.core.Stand ardWrapperValve .invoke(Standar dWrapperValve.j ava:210)
      at org.apache.cata lina.core.Stand ardContextValve .invoke(Standar dContextValve.j ava:174)
      at org.apache.cata lina.core.Stand ardHostValve.in voke(StandardHo stValve.java:12 7)
      at org.apache.cata lina.valves.Err orReportValve.i nvoke(ErrorRepo rtValve.java:11 7)
      at org.apache.cata lina.core.Stand ardEngineValve. invoke(Standard EngineValve.jav a:108)
      at org.apache.cata lina.connector. CoyoteAdapter.s ervice(CoyoteAd apter.java:151)
      at org.apache.coyo te.http11.Http1 1Processor.proc ess(Http11Proce ssor.java:870)
      at org.apache.coyo te.http11.Http1 1BaseProtocol$H ttp11Connection Handler.process Connection(Http 11BaseProtocol. java:665)
      at org.apache.tomc at.util.net.Poo lTcpEndpoint.pr ocessSocket(Poo lTcpEndpoint.ja va:528)
      at org.apache.tomc at.util.net.Lea derFollowerWork erThread.runIt( LeaderFollowerW orkerThread.jav a:81)
      at org.apache.tomc at.util.threads .ThreadPool$Con trolRunnable.ru n(ThreadPool.ja va:685)
      at java.lang.Threa d.run(Unknown Source)

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Did you make any changes that require you to restart/redeploy the application/server?

        Comment

        • ajos
          Contributor
          • Aug 2007
          • 283

          #5
          Originally posted by r035198x
          Did you make any changes that require you to restart/redeploy the application/server?
          hey r035198x,
          thanx for ur help,ive made the necessary changes and IT WORKED!!!! thanx once again...wud love to hear from u in the future also....:)

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by ajos
            hey r035198x,
            thanx for ur help,ive made the necessary changes and IT WORKED!!!! thanx once again...wud love to hear from u in the future also....:)
            Glad to hear it worked.
            I'm usually available on this forum. I would have given you my email if your handle wasn't ajos.

            Comment

            Working...