Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a servlet filter to detect absolute urls in jsp's

 
sanrocks polamarsetty
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was given this task. Do any one have any clue how to do it.

THE PROBLEM: The Web design time often creates absolute links in Web pages
(i.e., href="www.enasco.com/...."). They should be using relative links.

This is a problem because when testing on the test server, clicking a link
could take you to enasco.com (production) and the tester may not realize it.

SOLUTION: Create a Servlet Filter which will detect absolute links in the HTTP
response and collect them so that we can address the issue. We may display a
warning on the page, we may inject some Javascript to think link which will pop
up an alert box.. I'm not sure yet. But basically, we want to strongly
discourage the use of absolute links.

Suggested solution:

Before doFilter(), wrap the HttpResponse with something that will buffer the
response as its written. After doFilter(), you can look at this buffer to
detect any variation of "href='www.enasco.com....'. Collect these into a List
of some sort.


I'd suggest using the java.util.regex package to find occurences we're
interested in spotting.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64702
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really want to create a run-time solution for this? That seems crazy! Why do something at run-time, every time a request is made, that you can easily check at build time?

As part of your build, check for such problems, and send the file back to the designer if it fails.
 
sanrocks polamarsetty
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, i want to create in run time. That is my task.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18096
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sanrocks polamarsetty wrote:yes, i want to create in run time. That is my task.


In other words, you have to design, code and debug a software solution to a sloppy design process.

I wonder what else they're screwing up?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic