Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 661751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:18:07+00:00 2026-05-13T23:18:07+00:00

I have searched this topic on google a bit and seen some best practices.

  • 0

I have searched this topic on google a bit and seen some best practices. But I need some specific advice. I am working on a J2EE app that has servlets/Struts2/Call to DAO’s from JSP’s. So the app is all kinds of messed up. Most of the data is fetched via stored procedures, which are being called by iBatis ORM/Spring. Sometimes when an error happens on the SP side it will display an ugly message to the user such as below:

javax.servlet.ServletException: org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in debtowed.xml.  
--- The error occurred while applying a parameter map.  
--- Check the debtowed.getFormerTenantData.  
--- Check the statement (update procedure failed).  
--- Cause: java.sql.SQLException: ORA-06550: line 1, column 11:
PLS-00905: object package.GET_FORMER_ADDRESS is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

Caused by: java.sql.SQLException: ORA-06550: line 1, column 11:
PLS-00905: object package.GET_FORMER_ADDRESS is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

At this point the above information is displayed in the browser and logged to server.log.
However, I want to do following:

  • Present user with custom error page
  • log the errors in myapp.log instead of server.log (we do this in some other places as we use log4j)

Plese tell me what is the best way of doing this? Should I be adding something in web.xml? like a listener? will that be the only change or will I have to change existing code?

The code does not do any error checking. it just calls the SP like below

getSqlMapClientTemplate().queryForList("sp.getfmrAddy", paramMap);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:18:08+00:00Added an answer on May 13, 2026 at 11:18 pm

    I expect this is already solved in some way by Struts – so best check struts docco. If i were you i’d write an ExceptionFilter that can wrap your servlet calls:

    import java.io.IOException;
    
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.log4j.Logger;
    
    public class ExceptionFilter implements Filter{
    
    private static final Logger logger = Logger.getLogger(ExceptionFilter.class);
    private ExceptionService exceptionService = null;
    @Override
    public void destroy() {
        exceptionService.shutdown();
    }
    
    @Override
    public void doFilter(ServletRequest rq, ServletResponse rs, FilterChain chain) throws IOException, ServletException {
        try {
            chain.doFilter(rq, rs); // this calls the servlet which is where your exceptions will bubble up from
        } catch (Throwable t) {
            // deal with exception, then do redirect to custom jsp page
            logger.warn(t);
            exceptionService.dealWithException(t); // you could have a service to track counts of exceptions / log them to DB etc
            HttpServletResponse response = (HttpServletResponse) resp;
            response.sendRedirect("somejsp.jsp");
        }
    }
    
    @Override
    public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub
        exceptionService = new ExceptionService();
    }
    
    }
    

    and add this to your web.xml:

    <filter>
      <filter-name>ExceptionFilter</filter-name>
      <filter-class>com.example.ExceptionFilter</filter-class>
    </filter>
    
    <filter-mapping>
      <filter-name>ExceptionFilter</filter-name>
      <servlet-name>MyMainServlet</servlet-name>
    </filter-mapping>
    

    then add filter mappings for all your servlets.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched but apparently my google foo is weak. What I need is
I have googled and searched after this topic, but could not find any good
I have searched Google and Stackoverflow for this question, but I still don't understand
I have searched google but it seems no one has come across this issue.
I've searched for this a little but I have not gotten a particularly straight
I've searched (google and SO) about this topic and couldn't find a thorough answer
I'm new to asp.net mvc, but I've thoroughly searched on this topic everywhere. I've
I have searched the web for resolution of this error, but everything I have
i have a input tag which is non editable, but some times i need
I have searched google up and down but I can not find nearly any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.