Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

preventing compile-time errors when accessing included page directly  RSS feed

 
Bill Brasskey
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a JSP that contains only code. This JSP uses <%@ include file="" %>
to include other code-only JSPs. If a user attempts to access one of the included files directly, compile-time errors are thrown because beans and other variables that these included files use don't exist because they're declared in the including page. In the included pages, does anyone know of a way I can say "Hey, if this variable doesn't exist in memory, do this"???
Or would specifying an <error-page></error-page> in Jrun's web.xml file be the only way to prevent the compile-time errors? Surely there's another way.
*Any help/advice will be GREATLY appreciated.

-Brasskey
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66200
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My advice: factor the code out of the JSPs and into servlets.
 
Bill Brasskey
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Yes, I know....
But I was hoping to find a solution to this without having to re-write my application. In the future, I shall take your advice, but right now, I'd like to get this thing running. I do appreciate, though.

-Brasskey
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66200
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seriously, it will probably take you less time to refactor the app than to deal with the types of problems you are seeing now.

The only other piece of advice I could give is, if it is users directly accessing the JSPs that is creating most of your headaches, move the JSPs under the WEB-INF folder to prevent them from being directly served.
 
Bill Brasskey
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh...
That's a pretty good idea man, much obliged. And you're right, moving the code to servlets will be pretty easy as well since it's already written, it's just in the JSP.

-Brasskey
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!