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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:46:22+00:00 2026-06-13T08:46:22+00:00

Problem: I have a servlet that generate reports, more specifically the table body of

  • 0

Problem:

I have a servlet that generate reports, more specifically the table body of a report. It is a black box, we do not have access to the source code.

Nevertheless, its working satisfactory, and the servlet is not planned to be rewritten or replaced anytime soon.

We need to modify its response text in order to update a few links it generates to other reports, I was thinking of doing it with a filter that would find the anchor text and replace it using a regex.

Research:

I ran into this question that has a regex filter. It should be what I need, but then maybe not.

I am not trying to parse HTML in the strict sense of the parsing term, and I am not working with the full spec of the language. What I have is a subset of HTML tags that compose a table body, and does not have nested tables, so the HTML subset generated by the servlet is not recursive.

I just need to find / replace the anchors targets and add an attribute to the tag.

So the question is:

I need to modify the output of a servlet in order to change all links of the kind:

<a href="http://mypage.com/servlets/reports/?a=report&id=MyReport&filters=abcdefg">

into links like:

<a href="http://myOtherPage.com/webReports/report.xhtml?id=MyReport&filters=abcdefg" target="_parent">

Should I use the regex filter written by @ Jeremy Stein or is there a better solution?

  • 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-13T08:46:24+00:00Added an answer on June 13, 2026 at 8:46 am

    Assuming that the only part of the target A tags which vary is the query component of the href attribute, then this tested regex solution should do a pretty good job:

    // TEST.java 20121024_0800
    import java.util.regex.*;
    public class TEST {
        public static String fixReportAnchorElements(String text) {
            Pattern re_report_anchor = Pattern.compile(
                "<a href=\"http://mypage\\.com/servlets/reports/\\?a=report&id=([^\"]+)\">",
                Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
            Matcher m = re_report_anchor.matcher(text);
            return m.replaceAll(
                "<a href=\"http://myOtherPage.com/webReports/report.xhtml?id=$1\" target=\"_parent\">"
                );
        }
        public static void main(String[] args) {
            String input =
                "test <a href=\"http://mypage.com/servlets/reports/?a=report&id=MyReport&filters=abcdefg\"> test";
            String output = fixReportAnchorElements(input);
            System.out.println(output);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have a table that prints out vertical but I would like it
OK, here is the problem I have. I have a servlet that dynamically creates
I have a javax.servlet.Filter class that I would like to redirect urls. The problem
I have a simple jasper report that does not need a datasource so I
I'm facing the following problem. i have a servlet that serves a client request
I am using a javax.servlet.http.HttpServletRequest to implement a web application. I have no problem
I've seen that a few instances of this problem have been raised already. However,
Problem: I have a value that is set in $record, for instance 1.69. Then
Problem: I have a string that looks like this: [1=>2,3,4][5=>6,7,8][9=>10,11,12][13=>14,15][16=>17,18] Question: How can you
Problem: I have a value in a database table. This value can either contain

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.