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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:10:29+00:00 2026-06-06T19:10:29+00:00

I have a web application with multiple WARS. These WARS all perform different functions

  • 0

I have a web application with multiple WARS. These WARS all perform different functions but have many things in common : Css, Js, headers and footers, and certain jsps to output error messages and confirmations of transactions. For good maintainabilty I dont want to have any of these shared files in multiple locations, rather, one location so If I make an edit to one, it shows up in all. Just basic code management stuff, I don’t think I really need to explian this to anyone here on SO.

For Css and Js, I have a root War and I just absolutely address all of the <link> and <script> tags to it. For Headers and Footers (jsp fragments) I am using <c:import> and am grabing again from the root war. The final problem I have is shared jsps.

I often forward to these jsps after a user tries to perfrom an action which results in a change to our database to confirm that the transaction was completed or in other situations where I want to give formatted messages to the user. A Servlet might look like this…

public class sampleServlet extends ExtendedHttpServlet{ //ExtendedHttpServlet used to add common function to all of our HttpServlets including the foward function I use below. 
     public void doPost(HttpServletRequest request, HttpServletResponse response){

        //Do some preperation stuff here, then...

        try{

            ModelJob.insertNewControlMJob(user, submit);  //ModelJob is my inteface to our 'Job' Table Model... 
            submit.setSeqId(ModelJob.getSeqId(user, submit));
            EmailFactory.SUBMIT_NEW_EMAIL.sendCMAdminEmail(user, submit, null);
            EmailFactory.SUBMIT_NEW_EMAIL.sendUserEmail(user, submit, null);

            req.setAttribute("color","Green");
            req.setAttribute("message"," Job Successfully Submited. Sequece id : " + submit.getSeqId());
            forward("/WEB-INF/TransactionResult.jsp", req, resp); 
            return;

        }catch(Exception e){

            req.setAttribute("color","Red");
            req.setAttribute("message","Teradata failure : " + e.getMessage());
            forward("/WEB-INF/TransactionResult.jsp", req, resp);
            e.printStackTrace();
            return;

        }
     }
}

With this being the forward method I call above defined in the superclass ExtendedHttpServlet :

protected void forward(String destination, HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException 
{
    RequestDispatcher dispatcher = request.getRequestDispatcher(destination.toString());
    dispatcher.forward(request, response);
}

But with this I have to have a copy of the TransactionResult.jsp in all of my wars, and it makes maintenance a little bit of a pain.

My question is — Is there any way I could get my forward function to find jsps in other WARs to forward to. Or maybe could I include the jsp in my EAR and have the forward find the jsp files there. It is my understanding that jsps are just files and are compiled at runtime by special servlets, so I dont see why this wouldnt be possible?

Thanks for any advice / insight / help….

Edit Since some of you asked which server, I am currently on Websphere v 7.0

  • 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-06-06T19:10:30+00:00Added an answer on June 6, 2026 at 7:10 pm

    You can obtain the other servlet context by ServletContext#getContext() and then use its request dispatcher as available by ServletContext#getRequestDispatcher(). First you need to configure the server to enable the “cross context” option. This is by default disabled on most servers. It’s unclear which server you’re using, so here are just some hints: for Tomcat, check the crossContext attribute of context.xml and for Glassfish, check the crossContextAllowed property of glassfish-web.xml.

    Once done that, then you’ll be able to obtain the other ServletContext by its context path in servlet as follows:

    ServletContext otherServletContext = getServletContext().getContext("/otherContextPath");
    

    Then, you need to obtain a RequestDispatcher from it on the path of the desired resource and invoke the forward() on it hereby passing the current HTTP servlet request and response.

    otherServletContext.getRequestDispatcher("/WEB-INF/TransactionResult.jsp").forward(request, response);
    

    A completely different alternative is to create an entirely separate Java project (called a “Web Fragment Project” in Eclipse) wherein you put the shared JSPs in /META-INF/resources folder of the Java source folder. Finally deploy all your WARs with this Java project in flavor of a JAR file in /WEB-INF/lib folder (in Eclipse, adding the standalone Java project as “Deployment Assembly” of all web projects ought to be sufficient). You can access JSPs in /META-INF/resources folder as if they are in the current WAR.

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

Sidebar

Related Questions

I have a web application with two servlets and multiple mappings associated with each
In our web application, we have multiple small applications availables. Let us say A,B,C.
I have multiple servers across the globe, running the same web application. The user
I have an ASP.NET application running on multiple IIS6 web servers, with a SQL
I have multiple web applications (PHP) which are being served to different customers from
I have a web application that sends a single sms to multiple numbers via
I have a solution file containing multiple web applications and components. Mostly these web
I have a web application that runs multiple websites from one codebase. I have
I have a web application hosted on multiple servers some of which are on
I have multiple forms in a web application that have buttons which are currently

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.