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 6205283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:14:44+00:00 2026-05-24T05:14:44+00:00

I am new to struts and I would like to understand how do I

  • 0

I am new to struts and I would like to understand how do I handle logging for each layer(JSP/ActionForm, Action, DAO) of the application.

I notice as time goes by the error log file maybe too cluttered and unfriendly to view. How can I improve on the logging patterns to separate the errors thrown by each layer of the application?

and I couldnt find a way to handle exceptions encounter on jsp page as well.

Code Template for Action

public ActionForward perform(ActionMapping mapping, 
                              ActionForm form, 
                              HttpServletRequest request, 
                              HttpServletResponse response) 
   throws IOException, ServletException { 

   try {
         // calls the DAO
   }
   catch (CustomDAOException e) {
     log.error(e);
     // inform application there is an error
   }
   catch (Exception e) {
     log.error(e)
     // inform application there is an error
   }
}

Code Template for DAO

public void update() throw CustomDAOException {
try {
    // Prepare a statement to insert a record
    String sql = "INSERT INTO my_table (col_string) VALUES(?)";
    PreparedStatement pstmt = connection.prepareStatement(sql);

    // Insert 10 rows
    for (int i=0; i<10; i++) {
        // Set the value
        pstmt.setString(1, "row "+i);

        // Insert the row
        pstmt.executeUpdate();
    }
} catch (SQLException e) {
    throw new CustomDAOException(e);
}
  • 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-24T05:14:45+00:00Added an answer on May 24, 2026 at 5:14 am

    Set up an exception-handler in your struts-config, let all exceptions bubble up to that, and log them there. That will make all your exception-catching-and-logging code unnecessary.

    As for the JSP, don’t do anything error-prone in the JSP, do it in the action, then add the results to the request attributes.

    I’m guessing you might be using an ancient version of Struts 1, I’ve seen similar code where they had to catch exceptions in the actions, apparently because exception-handlers didn’t work with early versions of struts. That’s fixed now, the first thing you should do is upgrade the application to at least 1.2, preferably 1.3. Using an obsolete version of a web framework is a bad thing, there are security patches among the fixes you’re missing out on, so your application may be insecure.

    Looking at your sample code, it really doesn’t seem that bad. I don’t see the point of catching different types of exception in your actions (which might be clearer if I knew what you elided), but I don’t see bad practices like logging things in each layer and then rethrowing them (so that the same stack trace shows up repeatedly), or logging exceptions and returning null (so the calling code may not know anything went wrong), or just eating exceptions without a trace. If you give more specifics on what problems you want to solve maybe I or somebody else can be more helpful.

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

Sidebar

Related Questions

I am fairly new to jquery and I am working with jsp and struts
I want to implement a new language, and I would like to do it
Hai I would like to use Birt with Struts 2. But I am getting
I'm using some off-the-shelf OSGi bundles in my application and would like to repackage
I'm trying to start a new struts 2 project using maven (struts2 blank archetype)
I am new to struts 2. I am facing problem in filling Select tag
I am new to Struts . I downloaded Struts2 from its website. Now I
I recently got projects that runs on Struts and I am expecting more JSP
I have a Struts based web application that has a structure similar to the
I would like to store references to a bunch of structs in a collection.

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.