Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scriptlets

 
gurneeraj singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If scriplets are discouraged in JSP's, then how we can override _jspInit() method and _jspDestroy() method without scriptlets.

 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well I think first you need to look at this ...
 
gurneeraj singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my mistake, how can we override jspInit() and jspDestroy() method without using scriptlets.
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit, very usefull link,

Thanks
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well if you are overridding the jspInit or jspDestroy methods, then that means that you'll have some business logic in your JSP. But this is the whole concept of having scriptless JSPs. You try to separate business logic from presentation tier. So you are not supposed to override the jspInit or jspDestroy methods. I don't think there is any use of overridding them except using some business logic...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can we override jspInit() and jspDestroy() method without using scriptlets.

I agree with Ankit. Why would you override them ? That's the whole point. Don't use scriptlets, don't do java stuff in jsp, like overriding life cycle methods.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been working with JSP for 10 years (since version 0.92) and I have never had a need to override these methods.
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can override this methods using

<jsp:scriptlet> public void jspInit(){ //do something } </jsp:scriptlet>
 
Paul Clapham
Sheriff
Posts: 21152
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gurneeraj singh wrote:
If scriplets are discouraged in JSP's, then how we can override _jspInit() method and _jspDestroy() method without scriptlets.



Yes, scriptlets are discouraged in JSPs. And yes, you need scriptlets to override those methods. But there's no contradiction there. What is your question?
 
Kosala W.Abayagunawardene
Ranch Hand
Posts: 47
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Milton Ochoa wrote:you can override this methods using

<jsp:scriptlet> public void jspInit(){ //do something } </jsp:scriptlet>


I think you should use declaration for this as jspInit() is a method.this will not work.


should work
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice catch Kosala, I suppose no one noticed it earlier :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic