• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I make getRequest Dispatcher () return null?

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a snip from the API:The servlet receives as part of the URL, the 'next' page in the sequence. ie: servletName?nextPage=uiPage4.jsp

In the servlet code, I retrieve this parameter and do this:
But even if sendTo is some page that does not exist, disp will be non-null, and the forward will not fail as a 500 error, but rather a 404 error.

How do I trap the condition where someone tries to play monkey with the URL and requests a different page such as: servletName?nextPage=ImTryingToBeClever.jsp
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem is, there is a valid mapping for anything ending in .jsp: the JSP engine servlet. As a workaround, you could in case of .jsps use ServletContext.getResource() to see if the physical .jsp file is there before trying to get the request dispatcher.
- Peter
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Metadata to the rescue, mike! Be sneaky. Instead of:
servletName?nextPage=uiPage4.jsp
use servletName?nextPage=myFoo
Then have a hashmap that connects "abstract" page names to real page names. This is read out of an XML file or a properties file.
So your properties file would have:
myFoo=uiPage4.jsp.
That way you'll know instantly if the page they're requesting isn't a real page -- before you ever get a request dispatcher.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter and Kyle,

Thanks for your responses.

Peter, the solution you gave works very nicely. Thanks.

Kyle: I had actually thought of something very much like that. I coded that page way back at the start of development, and it's the only one that still uses the 'nextpage' parameter. I always thought it was kind of 'loose' to put the real page name right out there for all to see on the address bar. Laziness won out though.

Also, at this point, I'm doing minor tweaks and fixes to a 'deployed' application. So I need to furtively make small changes, test on my local instance of Tomcat, wait until everyone goes home, cross my fingers, and redploy on the deployment box.

Operations would have a fit.
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad it worked. Kyle's solution would, obviously, have been the one to go for had it been feasible.
- Peter
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, there's always the next release
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the next release *sigh*. Kyle, do you know any devious tricks to persuade management to allocate time for refactoring? No matter how much I insist that it makes good business sense, short-termism rules and applications succumb to entropy well before their time.
- Peter
 
mooooooo ..... tiny ad ....
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic