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

  • Home
  • SEARCH
  • 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 8782007
In Process

The Archive Base Latest Questions

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

As part of a Java webapp I’m working on I need to add a

  • 0

As part of a Java webapp I’m working on I need to add a prefix to some URIs are loaded from a database, e.g.

"controller.jsp?page=list"

becomes…

<a href="${legacyBaseUrl}/controller.jsp?page=list">...</a>

Easy. A problem arises though where some of the URIs in the database contain Javascript, e.g.

"javascript:window.open('controller.jsp?page=popup')"

What I’d like to be able to do is…

<a href="javascript:window.open('${legacyBaseUrl}/controller.jsp?page=popup')">...</a>

or better yet…

<a href="${legacyBaseUrl}/controller.jsp?page=popup" target="_blank">...</a>

I know I can just chop it apart with regular expressions, but I’m wary of treating this as a simple string manipulation problem, as the data has never been sanitized and there could be any Javascript in the database.

Is there a (relatively) simple way to parse Javascript properly in Java, and recognize/extract calls to window.open or other JS function?

I’ve looked briefly at stuff like Rhino or javax.script, but am a bit lost. Is this the right thing for my needs? Would a regex actually be enough? Any suggestions?

  • 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-13T20:27:23+00:00Added an answer on June 13, 2026 at 8:27 pm

    It seems you need fully functional HTML and probably java script parser. There are a lot such pure java implementations, e.g.

    http://www.webrenderer.com/products/server/product/

    HTML UNIT

    http://lobobrowser.org/java-browser.jsp

    Jakarta Cactus

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

Sidebar

Related Questions

As part of a project I'm working on, we're migrating from Velocity to JSP.
All, I'm working on a java webapp that we deploy in the Resin web
I need to add spring security to my webapp. My application uses spring an
I have a Java webapp, running in Tomcat 6, that loads RSS feeds from
I'm working on an old JSP webapp, that has basic 3 presentation areas: top
I have written provider part in java. Notification is sent to the APNs. Not
I'm trying to migrate an existing actionscript program (server part) to java (red5). However,
Considering this part of a Java class, private List<Object> components = new ArrayList<Object>(); private
I'm doing this as part of a Java tutorial, so it is probably not
I am deploying a JAX-WS client as part of a Java EE application on

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.