• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a method written in JSP be called from some other class?
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
y limit the qn to jsp ? how about servlets ? that's what jsps finally get converted into, right ?
And in both cases the answer is no. To understand this, think about the lifecycle of Servlets, do we
initialize them explicitly - no. After all servlets are intsantiated and maintained by the container.
Is it possible to get a handle to an existing Servlet object - no. There used to be a getServlets() method
in the context object which is now deprecated and would return null (according to Sun).

Theorotically it may be possible to say new Servlet() (I have never tried it out, so Iam not sure), however you couldnt call the Servlets doGet() or doPost() method, coz you cannot prepare the request and response objects,
for the same reason you cannot call init(). It may be possible, if for some bizzare reason(I cant think of any), you have your own public method inside the Servlet (& then u do a new Servlet() and call this method), but why would anybody do such a thing is quite beyond me. The same goes for static methods :-)

Tx,
Ram.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what javabeans are for.

Move your method to a bean and make it accessible to whatever JSPs need it.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
This is what javabeans are for.

Move your method to a bean and make it accessible to whatever JSPs need it.



cent percent AGREEMENT.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic