• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP conditions - non-scriplet  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, still learning all this cool J2EE stuff. So I need some direction.
When making a site that required authentication for some pages, and not using forms authentication or anything like that (trying to grasp concenpts), I need to check for the user being logged in on each protected page. No big deal. The way I have been doing it is simply putting an ID in the HttpSession and checking that in a scriplet on each page. If the ID is null, I direct them to the login page.
Now, what I am wondering is, what other ways do I have to do this. And more specifically, is there a way to do this that does not use scriplets?
Just looking for different ideas and opinions. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can head down the Model 2 path and use a Front Controller for your web app. That way, each 'hit' goes through the controller which can check for such things and either forward to the requested page or to the login page as appropiate.
hth,
bear
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, that is all fine and good. But what about other little things. For example, what if the user isn't logged in, so I want to display a username and password text fields in my main_header.jsp, but if the user is logged in, I want to replace that with a Welcome Jo Blow....
I don't know why I brought up the login crap, I meant the question to relate more along these lines.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I think I got it...
If it's just the scriplets that are violating your sensibilities, you can always use something like the JSTL 'if' tags that replace the scriplets with tag-centric notation. But, that is just a notation change, and you still have decision branches in the page.
I tend to write lots of custom tags, so a technique I frequently use is to abstract a construct into a custom tag. Any decision-making is handled within the custom tag code keeping the page stream-lined and abstracted.
Is that more along the lines of what you are after?
hth,
bear
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I think that is what I am after. Thanks Bear.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!