aspose file tools
The moose likes JSP and the fly likes can we write main() in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "can we write main() in jsp" Watch "can we write main() in jsp" New topic
Author

can we write main() in jsp

srinivas mallabathula
Greenhorn

Joined: Apr 12, 2011
Posts: 7
how can we write main() in JSP?then how it will execute?
Dieter Quickfend
Ranch Hand

Joined: Aug 06, 2010
Posts: 280
Yes, but why in the world would you want to do this?
You can put a main method in a jsp just like you can put any other method. The purpose of it eludes me, however. Especially since scriptlets are bad practice.

A JSP is just a kind of servlet, you know. A servlet is a java class. You can put a main method in at will. There's just no point to it.


Oracle Certified Professional Java Programmer
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12327
    
    1
You could not use a main() method for any kind of testing because a JSP depends on executing in the servlet container environment with a request and response , etc etc objects created by that environment.

Testing outside the servlet environment can be very helpful but you need to write classes that don't depend on the container.

Bill

Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: can we write main() in jsp
 
Similar Threads
jsp
Can we write a java program without main method?
can we write xml in a jsp page
main() in abstract class
Jsp and Web.xml