aspose file tools*
The moose likes Servlets and the fly likes How to create a servlet filter to detect absolute urls in jsp's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to create a servlet filter to detect absolute urls in jsp Watch "How to create a servlet filter to detect absolute urls in jsp New topic
Author

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

sanrocks polamarsetty
Greenhorn

Joined: Jul 05, 2012
Posts: 3
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

Joined: Jan 10, 2002
Posts: 60046
    
  65

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sanrocks polamarsetty
Greenhorn

Joined: Jul 05, 2012
Posts: 3
yes, i want to create in run time. That is my task.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15630
    
  15

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?


Customer surveys are for companies who didn't pay proper attention to begin with.
 
 
subject: How to create a servlet filter to detect absolute urls in jsp's
 
Similar Threads
HF's Chapter 13 Ques. 5
"After" filter?
Problem Servlet Filter
Filter problem - jar file not downloading
Question 65 Final mock exam - HFSJ