How to print out the exception caught in the servlet controller to JSP?

May I know how to print the Exception caught and the stacktrace thing? What i try to do this in the databaseErrata.jsp code was not given me any answer. Instead, causing a number of errors.
Below are my servlet controller code and databaseErrata.jsp code.
----$CATALINA_HOME/webapps/mvct/WEB-INF/classes/Action.java----
import java.io.*;
import java.sql.*;
import java.text.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
import foo.*;
public class Action extends HttpServlet
  public void doGet(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, IOException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    // find real web resource
    String forward = request.getServletPath();
//'forward' is a string variable consist of url
    if(forward.endsWith(".do"))
      forward = forward.substring(1, forward.length()
-3) + ".jsp";
    else
      throw new ServletException(
      "Action servlet called with illegal path: " +
forward); //display the defined error msg and error
url within the 'forward'
out.println("forward after forward.substring() = " +
forward + "</br>");
    // build and validate view page attributes
    HttpSession session = request.getSession();
    try
      byEmployeeId convert =
(byEmployeeId)session.getAttribute("convert");
      if(convert == null)
        session.setAttribute("convert", convert = new
byEmployeeId());
      convert.start("11145");
    catch(NamingException ex)
      request.setAttribute("exception", ex);
      forward = "databaseError.jsp";
    catch(SQLException ex)
      request.setAttribute("exception", ex);
      forward = "databaseErrata.jsp";
    catch(IllegalArgumentException ex)
      request.setAttribute("message", "<FONT COLOR='red'>"+ex.getMessage()+"</font>");
    // forward request
    RequestDispatcher rd =
request.getRequestDispatcher(forward);
    rd.forward(request,response);
public void doPost(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, IOException
      doGet(request, response);
}----$CATALINA_HOME/webapps/mvct/databaseErrata.jsp----
<% String message = (String)request.getAttribute("message"); %>
<HTML>
<HEAD>
<TITLE>databaseErrata.jsp Page</TITLE>
</HEAD>
<BODY>
<% if (message != null) { %>
Message = <%= message %>
<H1>databaseErrata.jsp Page</H1>
</BODY>
</HTML>

You're missing a closing curly bracket in the JSP page.
Also, this will only print the exception message. I would recommend passing on the whole Exception object.
ie request.setAttribute("theException", ex);
That way you have the exception object to print the stacktrace from.
However, you are doing this manually. The container can handle this stuff for you if you so wish.
Check the documentation on error pages. You are able to set up an error page in the web.xml, that all exceptions/errors get directed to.
something like:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/errorPages/debugError.jsp</location>
</error-page>
You then write the JSP page something like this
<%@ page language="java" %>
<%@ page isErrorPage="true" %>
<%@ page import="java.util.*, java.io.*" %>
<h1>Programming error <BR> FOR DEBUGGING PURPOSES ONLY</h1>
<p>This page is only for debugging purposes.  Should not be deployed to live environment.</p>
<p>Details of the error are as follows:</p>
<table border = 1 width=200>
<tr><td valign=top><strong>Error :</strong></td><td><%=exception.getMessage()%></td></tr>
<tr><td valign=top width='80%'><strong>Trace :</strong></td><td><pre><% exception.printStackTrace(new PrintWriter(out));%></pre></td></tr>
</table>
<br>Cheers,
evnafets

Similar Messages

  • How to print out answers using the form I created

    I created an application form for my company. People have submitted their applications, but I do not know how to print them out.
    Is there a way to copy the answers into the form and print that? Or something like that?
    I cannot just print the answers because it's over 100 pages and would be disorganized.
    I basically just need to know how to print out the form I created with the respondants answers.
    Thanks

    Here is what you can do...
    Open the form file
    Go to the View Responses tab
    Select the View menu in the upper right corner of the UI
    Select the Details View menu item on that menu
    The Details View pane will open on the right side of the window
    At the bottom of that pane there is a set of buttons
    The first button let's you print the detail view of the currently selected response
    The last button labeled Export will create a PDF file of the selected response
    Is that what you were trying to accomplish? I'll admit that we need to make print and export to PDF more discoverable and easier to get to - that was too many steps
    Randy

  • How to print out multilingual reports from the main report using Xliff temp

    Hi all,
    How to print out multilingual reports from the main report using Xliff temp?
    When I want main report call subtemplate and finish xliff tranlation
    <?for-each@section:INVOICE?><?end for-each?>
    <?import:xdo://XXIH.XXNR_XXINVPRINT_SUB.en.FI/?>
    <?start:body?><?call:Header?><?call:Line?><?call:Weights?><?call:Banks?><?end body?><?call:Footer?>
    Prints out fine with Finnish translation
    But if I want in main program to check what language is used e.g.
    if trx_number = 142 call Finnish translation and if trx_number =144,
    call English translation.
    <?for-each@section:INVOICE?><?end for-each?>
    <?if:TRX_NUMBER=’142’?>
    <?import:xdo://XXIH.XXNR_XXINVPRINT_SUB.en.FI/?>
    <?start:body?><?call:Header?><?call:Line?><?call:Weights?><?call:Banks?><?end body?><?call:Footer?>
    <?end if?>
    <?if: TRX_NUMBER=’144’?>
    <?import:xdo://XXIH.XXNR_XXINVPRINT_SUB.en.US/?>
    <?start:body?><?call:Header?><?call:Line?><?call:Weights?><?call:Banks?><?end body?><?call:Footer?>
    <?end if?>
    Prints out always in English and never the Finnish translation.
    Program goes fine to if branch but does not print out Finnish
    Does anybody know what could be wrong?
    BR
    Kari

    Thanks Amit,
    I have two layout, main-layout and sub-layout
    Main layout call subtemplate
    I have registered layout and xliff-file
    Main template
    Localized Templates
    File Name           Language Territory
    XXNS_INVOICE_MAIN.rtf      English
    SUB template
    Localized Templates
    File Name           Language Territory
    XXNS_INVOICE_SUB.rtf      English
    Translatable Template
    File Name           Language      Territory
    XXNS_INVOICE_SUB.rtf      English      United States
    Available Translations
    Language Territory Progress
    English Finland Complete
    If main report call subtemplate and finish xliff tranlation
    <?import:xdo://XXIH.XXNR_XXINVPRINT_SUB.en.FI/?>
    Prints out fine with Finnish translation
    But if I want in main program to check what language is used e.g.
    if....
    <?import:xdo://XXIH.XXNR_XXINVPRINT_SUB.en.FI/?>
    .....end if;
    if....
    <?import:xdo://XXIH.XXNR_XXINVPRINT_SUB.en.US/?>
    .....end if;
    Prints out always in English and never the Finnish translation.
    Program goes fine to if branch but does not print out Finnish
    Do you it's set up problem or program problem
    BR
    Kari

  • How to print out the position of 2 dimension arrays?

    there are 2 dimension arrays, how can print out the position of value than 4?
    for example
    0 2 3 2 2 2
    0 1 1 2 5 3
    1 2 3 3 2 1
    print out:
    The pos is ( 5,2).

    Hello
    If I understand your question correctly, you are trying to print out the indexes where the value in your matrix is greater than 4
    If this is the case, then what you need to use is nested for loops e.g.
    for (int i = 0; i< array[0].length; i++)
    for (int j = 0; j< array[].length; j++)
    int value = array[i][j];
    if (value > 4)
    System.out.println("The pos is (" + i + "," + j + ")" );
    Regarding the syntax I have used to get the size of the array, I am not sure if this is correct, but you should have an idea of what I am doing.
    Sajid

  • How to print out time as hr:min:sec without AM/PM?

    how to print out time as hr:min:sec without AM/PM
    since hr specifies AM/PM. Thank you. My first thought
    is that there exists a formatter to do this. My second
    thought is that if not I can convert the AM/PM in the
    DateFormat.MEDIUM to the right hour.

    import java.text.*;
    import java.util.*;
    public class Test {
        public static void main (String [] args) {
            SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
            Date d = new Date();
            System.out.println( format.format(d) );
    }

  • When I type a document and try to save it, there are black lines over my sentences, as if it had been highlighted, and that's how it prints out, just black lines

    when I type a document and try to save it, there are black lines over my sentences, as if it had been highlighted, and that's how it prints out, just black lines

    Hi Vickey, S,
    Sorry for the delay in response. Is it happening with all the files?
    Also, please write the steps you are taking to type in the document.
    You might try uninstalling and re installing the Reader in case it is happening with all the files.
    URL to install the Adobe Reader is Adobe - Adobe Reader download - All versions
    Thanks,
    Vikrantt Singh

  • How to find out web-inf path from the physical drive?

    How to find out web-inf path from the physical drive?
    I have some user profiles in web-inf directory.SO I want to know the path from root directory like
    d:/program files/allaire/jrun/appname/web-inf/profiles/username like that.
    Presently I am able to get the path upto the application directory and from that I am concatinationg web-inf/profiles/username .
    But it is giving problems when it is deployed under unix or linux.Because web-inf there it treats as WEB_INF
    SO I want to get the path of web-inf directory with out hard coding.
    Thanku

    String path = application.getRealPath("/WEB-INF/profiles/username");
    Note sure why you need this, but you don't need the real path to read the file - you can get an InputStream using the relative path. See ServletContext getResource() and getResourceAsStream().

  • How to find out which objects are at the end of the datafiles

    My Scenario is having a tablespace of 65G but the data is 5G and that is at the end of datafile for that we are not able to resize the datafile our though is to find out what are the objects at that end of datafiles and will either alter move <owner.tablename> move or alter index <owner.index> rebuld online.
    For that how to find out which objects are at the end of the datafiles.

    >
    My Scenario is having a tablespace of 65G but the data is 5G and that is at the end of datafile for that we are not able to resize the datafile our though is to find out what are the objects at that end of datafiles and will either alter move <owner.tablename> move or alter index <owner.index> rebuld online.
    For that how to find out which objects are at the end of the datafiles.
    >
    You may want to copy this and add it to your toolkit
    See 'What's at the End of the File?' in this Tom Kyte article from the Sept 2004 Oracle Magazine
    http://www.oracle.com/technetwork/issue-archive/o54asktom-086284.html
    And this AskTom blog shows you how to generate a script containing ALTER statements toresize your datafiles to the smallest possible. You can 'pick and choose' from the ALTER statements to do what you want.
    Then of course, you can use techniques from this article by Oracle ACE, and noted author, Jonathan Lewis
    http://jonathanlewis.wordpress.com/2010/02/06/shrink-tablespace/

  • How to find out which data control do the page layout components come from?

    hi,
    work in Jdev 11.1.2.3
    After have drag and drop data control into pages designer, how to find out which data control do the page layout component (such as a field in form layout) come from?
    --i cannot find data control related information in the property pallete for the page layout component.
    Regards.

    This information can be found in the page definition file.
    Select the field in the page and then click the binding tab.

  • How to find out if your Mac has the new Virus ?

    How to find out if your Mac has the new Virus, and how to fix it ???

    Helpful Links Regarding Flashback Trojan
    A link to a great User Tip about the trojan: Flashback Trojan User Tip
    A related link in the tip to a checker: Malware Checker Dowload Link
    A Google search can reveal a variety of alternatives on how the remove the trojan should your computer get infected. This can get you started.
    For now I recommend the User Tip from etressoft to detect and remove:
    Checking for and removing the "Flashback" trojan
    Kaspersky Flashback Trojan Site:Flashback Trojan Detection and Removal
    Also see Apple's article About Flashback malware.

  • Pages are not printing out correctly. I have tried to fix in the options, with no luck. It prints out with spaces in between the letters.

    When I go to print any page from an email, webpage, pdf file..the pages print out very wide fonts to the point where it is unreadable. I have tried to fix in the options with no luck. I can provide you with visuals if you need me to.

    Thanks very much! It works! The print / review print - print works like it is supposed to. The print is corrected and works great. Thanks again.

  • Can anyone explain to me how to print a page of Thumbnails of the same photo?

    Can anyone explain to me how to print a page of Thumbnails of the same picture, for wallet photos?

    In the print window select a print size that would allow many of the same photos on the page.  Click the Customize button and under settings select Multiple of the same photo per page.  In this screen shot I selected a size of 2x2. 
    Adjust the print size to get the number of photos per page that you want.
    OT

  • Every document I print also prints out a summary sheet at the end.  I want to disable this function

    Every document I print also prints out a summary sheet at the end.  i want to turn off this function.

    Check the print options in the dialog box.  If you don't have all this information displayed, click the circled arrow next to the printer name.  Click the program option drop down, it's the one with a horizontal line to the left and right, check the cover page option.  I can be set to before or after a print job.  Just say none.
    Regards,
    Captfred

  • Portal Runtime Error,See the details for the exception ID in the log file.

    Hi,
    I am Working on EP 7.0 .today am Getting this Error.
    Portal Runtime Error
    An exception occurred while processing a request for :
    iView : N/A
    Component Name : N/A
    The exception was logged. Inform your system administrator..
    See the details for the exception ID in the log file.
    Any Plz Give me idea to Solve this Problem........
    Reply ASAP..
    Thanks & Regards
    kumar

    Hi Kumar,
    Upload com.sap.logon.runtime.par(logon page .par file) into the portal.
    problem will be solved..
    regards
    Nizam

  • How to print out the Forms and Table fields relationship, data mapping?

    I create a forms and tables relationship inside the Form Developer 11g, once I created the Data relationships between the form data field and the Table column name. I don't have any command to print it out, such as Layout Wizard.
    Are there any programs on Windows platform can print it out?

    hi all,
    i have try to do this
    public static void Readbinary() throws Exception
              String file = "D:\\05-09.190501+0800";
              DataInputStream dis = new DataInputStream(new FileInputStream(file));
              //but then how to read the content ??????can you give me more hint ?????
    i have find the netflow v5 structure by C
    struct NFHeaderV5{
    uint16_t version; // flow-export version number
    uint16_t count; // number of flow entries
    uint32_t sysUptime;
    uint32_t unix_secs;
    uint32_t unix_nsecs;
    uint32_t flow_sequence; // sequence number
    uint8_t engine_type; // no VIP = 0, VIP2 = 1
    uint8_t engine_id; // VIP2 slot number
    uint16_t reserved; // reserved1,2
    struct NFV5{ 
    ipv4addr_t srcaddr; // source IP address
    ipv4addr_t dstaddr; // destination IP address
    ipv4addr_t nexthop; // next hop router's IP address
    uint16_t input; // input interface index
    uint16_t output; // output interface index
    uint32_t pkts; // packets sent in duration
    uint32_t bytes; // octets sent in duration
    uint32_t first; // SysUptime at start of flow
    uint32_t last; // and of last packet of flow
    uint16_t srcport; // TCP/UDP source port number or equivalent
    uint16_t dstport; // TCP/UDP destination port number or equivalent
    uint8_t pad;
    uint8_t tcp_flags; // bitwise OR of all TCP flags in flow; 0x10
    // for non-TCP flows
    uint8_t prot; // IP protocol, e.g., 6=TCP, 17=UDP, ...
    uint8_t tos; // IP Type-of-Service
    uint16_t src_as; // originating AS of source address
    uint16_t dst_as; // originating AS of destination address
    uint8_t src_mask; // source address prefix mask bits
    uint8_t dst_mask; // destination address prefix mask bits
    uint16_t reserved;
    but how to translate the structure to java,then get the data from the file ?
    Edited by: 903893 on Dec 21, 2011 10:52 PM

Maybe you are looking for