• Post Reply Bookmark Topic Watch Topic
  • New Topic

How private method are written in Jsp page  RSS feed

 
Mr Anil Kumar Pandey
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How private methods can be written in jsp page???
 
Mohamed Sanaulla
Bartender
Posts: 3169
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want methods in a jsp? Sounds like a bad design. JSPs are meant for View only and all the operation had to be handled by the Controller or the Model classes.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should never be any Java code in a JSP page.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How? Very easily. Just using the declaration tags:

<%!
private void myFunction(String s1){
// function that does something for the JSP.
}
%>

Should you? No, probably not. There are much better places to put 'function' logic. Either in a bean or a custom tag.

 
Mr Anil Kumar Pandey
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:How? Very easily. Just using the declaration tags:

<%!
private void myFunction(String s1){
// function that does something for the JSP.
}
%>

Should you? No, probably not. There are much better places to put 'function' logic. Either in a bean or a custom tag.



In an interview i was asked
ok if i write private method in declaration then how that can be called from other pages.?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!