Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing Scriptless JSP

 
Durgaprasad Guduguntla
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please take a look at the following JSP of a web application where the BASIC authentication is enabled. The client logs into the application with his userid and password. Three roles are provided the access - chairman, manager and engineer. The JSP determines the username and role from the request object and stores it in the session.

Can someone explain as to how we can rewrite this scriptlet using JSTL and EL?
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might consider posting what your ideas are, and what you are thinking. For instance "I thought I would try 'X', but if I did that then I couldn't figure out how to do 'Y'". Otherwise, people might think they were doing your homework for you.

--Dale--
 
Durgaprasad Guduguntla
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dale,

I am figuring out as to how call request object methods from EL.

For example, request.getRemoteUser() can be written in EL as

${pageContext.request.remoteUser}

Similarly I want to know is there any way to call request.isUserInRole("chairman") in EL?

Thanks,

Durga
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just created an instance variable called "shipValid" in a plain old Java bean, and asked Eclipse to generate getters and setters (Eclipse created "isShipValid" and "setShipValid"). Then I put a <jsp:useBean id="test"...> in a jsp and tried ${test.shipValid}. It said "false". So that works. I guess your boolean takes a parameter, though. That might be a problem.

--Dale--
[ January 27, 2005: Message edited by: Dale Seng ]
 
sundar katluri
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand this question may be for learning towards JSTL and EL but still
how do we write it? .. may be it is discouraged to write this much code in
jsp (I mean we use servlet for this purpose) and call only jsp with ${sessionScope.userName} kind of syntax ... what do you say guys??
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could still stay scriptless by coding your own tag handler. Like I indicated earlier, I don't see a way to pass-in the parameter. If you were using MVC, you would have set the role in the servlet anyway ;-)

--Dale--
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic