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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:29:07+00:00 2026-05-28T13:29:07+00:00

I’m trying to migrate an existing application from IIS with ServletExec to tomcat. I

  • 0

I’m trying to migrate an existing application from IIS with ServletExec to tomcat. I got everything working except for the case where there is a servlet chain with two servlets.

The first servlet does some processing and the second servlet does some translation.

request-->ProcessServlet--> (untranslated html) -->TranslateServlet --> response

In my case, I can call the ProcessServlet and it produces html with untranslated tags. The second servlet looks like it takes the html, locates well known translation tags and translates them and produces readable outupt to the browser.

From googling, looks like servlet chaining using servlet aliasing is no longer supported/recommended( from this page) and the same functionality can be achieved with filters but the classes have to implement an interface but unfortunately in my case I have to work with the existing class files.

This page specifies the concept but has no examples.

Also from this page

How to Configure a Servlet Chain Using Servlet Aliasing

Using the Servlet Aliasing subsection of the setup section in the
Administration Tool, a list of servlets can be named for a particular
URL request. In the servlets table, when adding a new mapping, you are
allowed to enter a comma-separated list of servlets in the order in
which they should be invoked when a request arrives for that
particular URL. This configures a servlet chain to be invoked every
time a request that matches the URL arrives.

Can anyone specify an example or point me in the right direction as to how to get this chain to work from web.xml?

UPDATE:

Per kschneid’s outline in his answer, here’s the full implementation that worked for me

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class TranslateFilter implements Filter {

  private FilterConfig config = null;

  public void init(FilterConfig config) throws ServletException {
    this.config = config;
  }

  public void destroy() {
    config = null;
  }

  public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain) throws IOException, ServletException {

        HttpServletResponse httpResponse = (HttpServletResponse) response;
        MyHttpServletResponseWrapper processResponse  =   new MyHttpServletResponseWrapper(httpResponse);
        chain.doFilter(request, processResponse );
        String content = processResponse.toString();
        config.getServletContext().log("CONTENT: " + content);
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        MyHttpServletRequestWrapper processResponseAsRequest = new MyHttpServletRequestWrapper(httpRequest, content);

        RequestDispatcher dispatch = request.getRequestDispatcher("/Translate");
        response.setContentType("text/html");
        dispatch.forward(processResponseAsRequest, response); // forward to translate servlet with response from process servlet as the request and the original response
  }

}

class MyHttpServletResponseWrapper 
  extends HttpServletResponseWrapper {

  private StringWriter sw = new StringWriter();

  public MyHttpServletResponseWrapper(HttpServletResponse response) {
    super(response);
  }

  public PrintWriter getWriter() throws IOException {
    return new PrintWriter(sw);
  }

  public ServletOutputStream getOutputStream() throws IOException {
    throw new UnsupportedOperationException();
  }

  public String toString() {
    return sw.toString();
  }
}

class MyHttpServletRequestWrapper 
  extends HttpServletRequestWrapper {
    private String content;
    public MyHttpServletRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    public MyHttpServletRequestWrapper(HttpServletRequest request, String content) {
        super(request);
        this.content = content;
    }

    public ServletInputStream getInputStream()
    {
        return new MyServletInputStream(content);
    }

    public BufferedReader getReader()
    {
        InputStreamReader in= new InputStreamReader(getInputStream());
        return new BufferedReader(in);
    }
  }

class MyServletInputStream extends ServletInputStream
{
    private InputStream is;

    public MyServletInputStream(String content)
    {
        is = new ByteArrayInputStream(content.getBytes());
    }

    public int read() throws IOException
    {
        return is.read();
    }
}
  • 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-28T13:29:08+00:00Added an answer on May 28, 2026 at 1:29 pm

    I’m not really familiar with the implementation details of servlet chaining, but here’s a general approach that might work. Map the two servlets to different URLs:

    <servlet-mapping>
        <servlet-name>process</servlet-name>
        <url-pattern>/process</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>translate</servlet-name>
        <url-pattern>/translate</url-pattern>
    </servlet-mapping>
    

    Then map a filter to the process servlet:

    <filter-mapping>
        <filter-name>processChain</filter-name>
        <servlet-name>process</servlet-name>
    </filter-mapping>
    

    The processChain filter would do something like:

    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        ServletResponseWrapper processResponse = ...; // response buffer
        chain.doFilter(request, processResponse); // let process servlet populate response buffer
        ServletRequestWrapper processResponseAsRequest = ...; // use processResponse to create request for translate servlet
        RequestDispatcher dispatch = request.getRequestDispatcher("/translate");
        dispatch.forward(processResponseAsRequest, response); // forward to translate servlet with response from process servlet as the request and the original response
    }
    

    …or something like that 😉

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.